Hey guys!
I’m new to the forums (New to Unity altogether actually) so I apologize in advance for any foolishness.
I’m having an issue with getting a platform (I’m using a simple cube) to move forward and backward on the x axis. Now, while I know that there are other, probably better methods for doing so, I really just want to know why this specific script does not work properly. I tried rearranging the script multiple times; sometimes it’d only move negatively, sometimes it’d only move positively. I even added print() commands to see where the problem lies. At one point I got the log to cycle true and false, but at the moment, the log remains empty and the cube only travels positively on the x axis.
I appreciate any help you guys could offer as I absolutely need to find out what is wrong with this script. It’s driving me crazy! :neutral:
function Update ()
{
Move();
}
function Move()
{
var x = gameObject.transform.position.x;
var movingForwardBool : boolean = true;
var movingCounterInt : int = 0;
if (movingForwardBool == true)
{
for (v = 0; v <= 9; v++)
{
movingCounterInt += 1;
gameObject.transform.position.x = gameObject.transform.position.x + .01;
if (movingCounterInt == 0)
{
movingForwardBool = true;
print("movingForward is true");
}
}
}
if (movingForwardBool == false)
{
for (n = 0; n<= 9; n++)
{
movingCounterInt -= 1;
gameObject.transform.position.x = gameObject.transform.position.x - .01;
if (movingCounterInt == 10)
{
movingForwardBool = false;
print("movingForward is false");
}
}
}
}