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

Enemy ia fliping when hitting object

$
0
0
Hi, I want my enemies to flip and go the opposite direction they are comming from, so far when they hit Bush, and Bush2 it works, but I also want to do that when hitting an enemy, ty! public float speed; Rigidbody2D rb2D; SpriteRenderer sprite; private bool canMove; // Use this for initialization void Start () { rb2D = GetComponent (); sprite = GetComponent (); int rand = Random.Range(0, 2); if (rand == 0) { speed = -speed; } } // Update is called once per frame void Update () { if (canMove == true) { transform.Translate (speed * Time.deltaTime, 0, 0); } } void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Bush2") { sprite.flipX = true; speed = -1; } if (collision.gameObject.tag == "Bush") { sprite.flipX = false; speed = -1; } if (collision.gameObject.tag == "Enemy") { sprite.flipX = true; speed = -1; } if (collision.gameObject.CompareTag ("Ground")) { canMove = true; } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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