Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Need help with enemy script (C#)(2D)

$
0
0
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); }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>