- Home /
 
Need help with enemy script (C#)(2D)
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);
 }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Is the Player Being Looked at 1 Answer
EnemyAI C# Error 1 Answer
How to make an AI like slender ? 1 Answer
AI Following Problem 1 Answer
sprite changes z position without any input to do so 1 Answer