Back button is not working

Hello Vivek,

Wheb you say not working, what is the expected behavior you are seeking?

Should the button just be responding to mouse inreraction, perhaps changing colour when the mouse is hovering above it, or when the mouse button is pressed.

Or, should the button be loading another scene or other behavior.

Please advise and we will see if we can help :slight_smile:

Hello Rob,

It should go back to start screen.


I just did as per the instructions.

1 Like

Hi Vivek,

For the “back” text have you changed the scene name to “Start”? It looks like when you click the button the code is running but the scene isn’t changing as it’s jumping to the current scene. It should look like this.. Also I would have a look at your debug.Log script in the LevelManager I think you’ve got your quotes on the wrong part as it’s outputting “Level load request for +name”. I believe you should have the following as your code:

Debug.Log("Load level request for: "+name); 

With the quotes ended before the + and then the level name as a string after the +.

2 Likes

It is same as your image.


why these errors warnings?

I’m using unity 2017 and visual studio community.

1 Like

It worked (BackButton),
I added a new script, but it showing me a new error can you please take a look at it.

1 Like

Hi Dude,

This usually happens when you have deleted a script from a gameobject or renamed it.

You could play the game hit the pause button and then select the warning it should then highlight the offending gameobject in the hierarchy which you can then resolve by adding the script back to it etc.

2 Likes

Hi Vivek,

While you got it working and that’s great it’s important to understand WHY it went wrong. You’re using the following:

public void LoadLevel(String name) {
Debug.Log("Level load requested  for: +name");
Application.LoadLevel("Game");
}

Lets break it down into plain English:

public void LoadLevel(String name) {

means "I’m going to give you a new command known as LoadLevel, other areas of the game will need to talk to it so it’s going to be public and it doesn’t have to give anything back only run itself so it will be void of a return figure however it does need a string of text which we’ll call name. This is the scene name that we’re going to load.

Debug.Log("Level load requested  for: +name");

This tells the engine to output an console log which simply states “Level load requested for: +name”. That’s not very helpful as we want to actually see the name we’re passing into it so the quotes need to end after the colon so we have Debug.Log("Level load requested for: "+name); now what the computer will do is output "Level load requested for: " then the name of the level we’re trying to load. This is helpful as we can make sure the correct level is attempted to be loaded.

Application.LoadLevel("Game");

This part tells Unity to load the scene named “Game”. It doesn’t matter what you pass in as “name”, Unity will always try to load the “Game” scene hence why it seems like your button isn’t working. What you’re looking for instead is Application.LoadLevel(name); this way Unity will try to load the scene of the string of text that you’re passing into it.

As for the errors, this is due to you using a newer version of Unity. Please refer back to one of the very first videos where you are shown how to download v4.6

2 Likes

Still not worked, if I write as you say it shows add name in build setting.

1 Like

Did you remember to rebuild(F8) your code before hitting play? There’s no reason for “+name” to be shown in the debug log if it’s outside of quotes unless Unity2017 has changed it(again you should be using the 4.6 version not the latest one).

2 Likes

Hi Vivek,

I dipped out of this one as it looked like you were getting lots of help.

Could I suggest zipping up your project files and uploading the project into your next reply, it will be a lot easier to just open the project and look for the issue than going back and forth.

There’s no issue using a more recent version of Unity for this course, the differences between the API in the original course version (4.6.3) and the current version are documented and available in lecture 8.

Pop your zip file up and I will happily review and provide you with a list of any changes and why they are needed etc.

Ok,
Rob, I have completed it by adding seperate scripts.
Here is my game!

1 Like

So, all working now?

1 Like

Yep!

1 Like

Great! Well done :slight_smile:

1 Like

New problem,


Showing error, cannot implicitly convert int to bool.
Changed many things in the code as per the requirement of unity 2017 but stuck here in the morning.
Need help again.

In an if statement you need to use a double equals ie == to compare two variables.

2 Likes

Thanks,
I missed that.
Actually, I was testing on my own and had not watcher further tutorial.

But, can you please help me in chapter 83 making win simulation.
It is showing many errors in my script.
I skipped that tutorial for now.

1 Like

Hi Vivek,

It would be best to create a topic for a specific question, that way, if other students have either experienced the same issue, or future students do, the conversation and eventual solution are easy to follow. When there are multiple questions in the same topic it can get quite hard to follow.

It’s also more useful to post the script and format it using the code formatting supported by the forum rather than screenshots. Screenshots are really useful however for viewing details from the Unity editor, but for code, please code/paste.


See also;

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms