TO SQUASH: Fixed shark death.
This commit is contained in:
@@ -153,40 +153,50 @@ public class Shark : MonoBehaviour
|
|||||||
animator.SetBool("canMove", true);
|
animator.SetBool("canMove", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do stuff only if the spawn animation has finished.
|
if (killed)
|
||||||
if (spawnFinished)
|
|
||||||
{
|
{
|
||||||
if (killed && !isDead)
|
if (!isDead)
|
||||||
{
|
{
|
||||||
isDead = true;
|
isDead = true;
|
||||||
animator.SetTrigger("killed");
|
|
||||||
|
if (animator != null)
|
||||||
|
{
|
||||||
|
// Keep death state stable even if Any State transitions exist for movement.
|
||||||
|
animator.SetBool("canMove", false);
|
||||||
|
animator.Play("SharkDeath", 0, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
audioSource.PlayOneShot(deathSound);
|
audioSource.PlayOneShot(deathSound);
|
||||||
player.score += sharkKillPoints;
|
player.score += sharkKillPoints;
|
||||||
StartCoroutine(DestroyShark());
|
StartCoroutine(DestroyShark());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do stuff only if the spawn animation has finished.
|
||||||
|
if (spawnFinished)
|
||||||
|
{
|
||||||
|
UpdateMovement();
|
||||||
|
animator.SetInteger("angle", angle);
|
||||||
|
|
||||||
|
if (!isAngry && !isTired && Random.value < angryProbability)
|
||||||
{
|
{
|
||||||
UpdateMovement();
|
isAngry = true;
|
||||||
animator.SetInteger("angle", angle);
|
angryTimer = angryDuration;
|
||||||
|
audioSource.PlayOneShot(angrySound);
|
||||||
|
}
|
||||||
|
|
||||||
if (!isAngry && !isTired && Random.value < angryProbability)
|
if (isAngry && !isTired && angryTimer <= 0f)
|
||||||
{
|
{
|
||||||
isAngry = true;
|
isAngry = false;
|
||||||
angryTimer = angryDuration;
|
isTired = true;
|
||||||
audioSource.PlayOneShot(angrySound);
|
audioSource.PlayOneShot(tiredSound);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAngry && !isTired && angryTimer <= 0f)
|
if (isAngry)
|
||||||
{
|
{
|
||||||
isAngry = false;
|
angryTimer -= Time.fixedDeltaTime;
|
||||||
isTired = true;
|
|
||||||
audioSource.PlayOneShot(tiredSound);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isAngry)
|
|
||||||
{
|
|
||||||
angryTimer -= Time.fixedDeltaTime;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,11 +291,22 @@ public class Shark : MonoBehaviour
|
|||||||
|
|
||||||
private IEnumerator DestroyShark()
|
private IEnumerator DestroyShark()
|
||||||
{
|
{
|
||||||
// Wait two loops of the death animation before destroying the shark object.
|
// Wait until the death state has looped twice, with a timeout fallback so this cannot hang forever.
|
||||||
yield return new WaitUntil(
|
float elapsed = 0.0f;
|
||||||
() => animator.GetCurrentAnimatorStateInfo(0).IsName("SharkDeath") &&
|
const float maxWaitSeconds = 5.0f;
|
||||||
animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 2.0f
|
|
||||||
);
|
while (elapsed < maxWaitSeconds)
|
||||||
|
{
|
||||||
|
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
|
||||||
|
if (stateInfo.IsName("SharkDeath") && stateInfo.normalizedTime >= 2.0f)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed += Time.deltaTime;
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
|
||||||
Destroy(gameObject);
|
Destroy(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +347,19 @@ public class Shark : MonoBehaviour
|
|||||||
|
|
||||||
public void KillShark()
|
public void KillShark()
|
||||||
{
|
{
|
||||||
|
if (killed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
killed = true;
|
killed = true;
|
||||||
|
|
||||||
|
if (animator != null)
|
||||||
|
{
|
||||||
|
// Stop movement-related Any State transitions, then force the death animation.
|
||||||
|
animator.SetBool("canMove", false);
|
||||||
|
animator.ResetTrigger("killed");
|
||||||
|
animator.Play("SharkDeath", 0, 0.0f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user