TO SQUASH: Added FruitBall prefab, animation, and script. Updated BallSpawner to spawn FruitBalls.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FruitBall : MonoBehaviour
|
||||
{
|
||||
private Animator animator;
|
||||
|
||||
public AudioClip spawnSound;
|
||||
|
||||
public AudioClip bounceSound;
|
||||
|
||||
public AudioClip hitSound;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private Vector2 speed;
|
||||
|
||||
private float speedMultiplier = 1.0f;
|
||||
|
||||
private float speedIncreaseTimer = 0.0f;
|
||||
|
||||
// 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(Mathf.Sign(Random.Range(-1f, 1f)) * 0.0001f,
|
||||
Mathf.Sign(Random.Range(-1f, 1f)) * 0.0001f);
|
||||
|
||||
audioSource.PlayOneShot(spawnSound);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
|
||||
|
||||
if (stateInfo.IsName("FruitBallMove")) {
|
||||
transform.Translate(speed * speedMultiplier);
|
||||
}
|
||||
|
||||
if (speedIncreaseTimer > 0.0f)
|
||||
{
|
||||
speedIncreaseTimer -= Time.deltaTime;
|
||||
if (speedIncreaseTimer <= 0.0f)
|
||||
{
|
||||
speedMultiplier = 1.0f; // Reset the speed multiplier to 1x
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Wall") || collision.gameObject.CompareTag("Ball"))
|
||||
{
|
||||
ContactPoint2D contact = collision.GetContact(0);
|
||||
speed = Vector2.Reflect(speed, contact.normal);
|
||||
|
||||
if (collision.gameObject.CompareTag("Ball"))
|
||||
{
|
||||
speedIncreaseTimer = 2.0f; // Reset the timer to 2 seconds
|
||||
speedMultiplier = 50.0f; // Set the speed multiplier to 7x
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc75c31387827597c81cd1228c0e31ac
|
||||
Reference in New Issue
Block a user