Files
Barrack-Unity/Assets/Scripts/Game/Balls/EyeBall.cs
T

37 lines
1.0 KiB
C#
Raw Normal View History

2026-08-04 21:23:39 -04:00
using UnityEngine;
2026-08-05 01:23:47 -04:00
public class EyeBall : BallBase
2026-08-04 21:23:39 -04:00
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
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);
2026-08-05 01:23:47 -04:00
// TODO: Adjust eye ball direction based on the player's bar if active.
2026-08-04 21:23:39 -04:00
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);
}
}
}