So I a script where the ufo is supposed to go the other direction when it touches a certain object, but the bool I am using to do this wont go true on the collision, here is my script for it.
float speed = 3f;
public bool returnRight;
void Start () {
}
void FixedUpdate (){
if (returnRight == true){
MoveLeft ();
}
if (returnRight == false) {
MoveRight ();
}
}
void OnCollisionEnter2D (Collision2D other){
if (other.transform.tag == "ReturnRight1") {
returnRight = true;
}
if (other.transform.tag == "ReturnLeft1") {
returnRight = false;
}
}
void MoveRight (){
transform.Translate(Vector3.right * speed * Time.deltaTime);
}
void MoveLeft (){
transform.Translate(Vector3.left * speed * Time.deltaTime);
}
↧