TO SQUASH: Fixed issue with yummy missed sound playing multiple times.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public abstract class YummyBase : MonoBehaviour
|
||||
{
|
||||
@@ -20,6 +21,8 @@ public abstract class YummyBase : MonoBehaviour
|
||||
|
||||
private float missedTimer = 0f;
|
||||
|
||||
private bool isMissed = false;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
@@ -32,7 +35,7 @@ public abstract class YummyBase : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (isObtained)
|
||||
if (isObtained || isMissed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -41,10 +44,12 @@ public abstract class YummyBase : MonoBehaviour
|
||||
|
||||
missedTimer += Time.fixedDeltaTime;
|
||||
|
||||
if (missedTimer >= 5f)
|
||||
if (missedTimer >= 5f && !isMissed)
|
||||
{
|
||||
isMissed = true;
|
||||
audioSource.PlayOneShot(missedSound);
|
||||
animator.SetTrigger("missed");
|
||||
StartCoroutine(DestroyYummy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +90,9 @@ public abstract class YummyBase : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void DestroyYummy()
|
||||
public IEnumerator DestroyYummy()
|
||||
{
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user