I have a script that detects whether an object is on the right of the screen or the left of the screen. If it is on the right it will translate on the x axis left, if it’s on the left, it will translate to the right. I have got this to work on the y axis for a previous object, but now they either go up or down on the y axis even though I have it set to translate on the x axis. Here is the script that I am working on.
#pragma strict
var speed: int = 5;
var isLeft: boolean = false;
var isRight: boolean = false;
function Start ()
{
}
function Update ()
{
if(transform.position.x >= 11)
{
isRight = true;
isLeft = false;
}
if(transform.position.x <= -11)
{
isLeft = true;
isRight = false;
}
if(isRight == true)
{
transform.Translate(Vector3(-speed, 0, 0) * Time.deltaTime);
}
if(isLeft == true)
{
transform.Translate(Vector3(speed, 0, 0) * Time.deltaTime);
}
}