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

36 lines
1.0 KiB
C#
Raw Normal View History

2026-07-26 00:59:17 -04:00
using UnityEngine;
2026-08-05 01:23:47 -04:00
public class BasicBall : BallBase
2026-07-26 00:59:17 -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);
if (stateInfo.IsName("BasicBallMove")) {
transform.Translate(speed);
}
}
void OnCollisionEnter2D(Collision2D collision)
{
2026-08-03 01:47:14 -04:00
if (collision.gameObject.CompareTag("Wall") ||
collision.gameObject.CompareTag("BasicBall") ||
collision.gameObject.CompareTag("FruitBall"))
2026-07-26 00:59:17 -04:00
{
ContactPoint2D contact = collision.GetContact(0);
speed = Vector2.Reflect(speed, contact.normal);
}
}
}