using UnityEngine; public class EyeBall : MonoBehaviour { private Animator animator; public AudioClip spawnSound; public AudioClip bounceSound; public AudioClip hitSound; private AudioSource audioSource; private Vector2 speed; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { audioSource = GetComponent(); animator = GetComponent(); speed = new Vector2(Random.Range(-0.05f, 0.05f), Random.Range(-0.05f, 0.05f)); audioSource.PlayOneShot(spawnSound); } // Update is called once per frame void FixedUpdate() { AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); if (stateInfo.IsName("EyeBallMove")) { transform.Translate(speed); } } void OnCollisionEnter2D(Collision2D collision) { // EyeBall only bounces off walls, not other balls if (collision.gameObject.CompareTag("Wall")) { ContactPoint2D contact = collision.GetContact(0); speed = Vector2.Reflect(speed, contact.normal); } } }