TO SQUASH: Fixed oozeball split animation.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class OozeBall : MonoBehaviour
|
||||
{
|
||||
@@ -16,19 +17,24 @@ public class OozeBall : MonoBehaviour
|
||||
|
||||
public AudioClip stoppedSound;
|
||||
|
||||
public BallSpawner spawner;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
private Vector2 speed;
|
||||
|
||||
private float splitTimer = 30.0f;
|
||||
private float splitTimer = 10.0f;
|
||||
|
||||
private float tickTimer = 1.0f;
|
||||
private float tickTimer = 0.5f;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
animator = GetComponent<Animator>();
|
||||
spriteRenderer = GetComponent<SpriteRenderer>();
|
||||
speed = new Vector2(Random.Range(-0.002f, 0.002f), Random.Range(-0.002f, 0.002f));
|
||||
|
||||
audioSource.PlayOneShot(spawnSound);
|
||||
@@ -39,7 +45,7 @@ public class OozeBall : MonoBehaviour
|
||||
{
|
||||
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
|
||||
|
||||
if (stateInfo.IsName("OozeBallMove")) {
|
||||
if (stateInfo.IsName("OozeBallMove") || stateInfo.IsName("OozeBallSplit")) {
|
||||
transform.Translate(speed);
|
||||
}
|
||||
|
||||
@@ -48,13 +54,12 @@ public class OozeBall : MonoBehaviour
|
||||
|
||||
if (splitTimer <= 0.0f)
|
||||
{
|
||||
Split();
|
||||
Destroy(gameObject);
|
||||
animator.SetTrigger("split");
|
||||
}
|
||||
|
||||
if (tickTimer <= 0.0f)
|
||||
{
|
||||
tickTimer = 1.0f;
|
||||
tickTimer = 0.5f;
|
||||
audioSource.PlayOneShot(timerSound);
|
||||
}
|
||||
|
||||
@@ -72,9 +77,26 @@ public class OozeBall : MonoBehaviour
|
||||
|
||||
void Split()
|
||||
{
|
||||
animator.SetTrigger("split");
|
||||
StartCoroutine(SplitCoroutine());
|
||||
}
|
||||
|
||||
private IEnumerator SplitCoroutine()
|
||||
{
|
||||
spriteRenderer.enabled = false;
|
||||
audioSource.PlayOneShot(splitSound);
|
||||
// TODO: Implement the logic for splitting the OozeBall into smaller balls
|
||||
|
||||
for (int i = 0; i < Random.Range(5, 8); i++)
|
||||
{
|
||||
Vector3 spawnPosition = transform.position +
|
||||
new Vector3(Random.Range(-0.12f, 0.12f), Random.Range(-0.12f, 0.12f), 0);
|
||||
spawner.SpawnBallOfType("BasicBall", spawnPosition);
|
||||
}
|
||||
|
||||
spawner.FixCollisions();
|
||||
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
void Halt()
|
||||
|
||||
Reference in New Issue
Block a user