moved to answers
When the ball moves on the X-axis the variable stays the same, i dont know what has gone wrong, please help.
Simple - show your code. (use the Code: <> button above the dialogue box ^^^)
Assuming that “Location2” is a variable, you can set it equal to the current value of the ball’s X coordinate with something like
Location2 = ball.transform.position.x;
There is no way to make a variable “automatically” update to match something else. Instead, you have to write code to update the variable. There are two general strategies for this:
-
Events: When the thing changes, it sends out a notification to anyone who needs to know, so that they can update at exactly that time.
-
Polling: As time passes, just keep checking over and over to see if anything is different from last time you looked.
For a new Unity user, option #2 will usually be easier. The main way to use polling in Unity is to put your code in an Update() function. Update automatically gets called once every frame of your game, so any code you put there will run once per frame, and any variables you set there will never be more than one frame out-of-date.