TO SQUASH: Fixed collision issues with the shark.
This commit is contained in:
@@ -98,6 +98,8 @@ public class Player : MonoBehaviour
|
||||
|
||||
private float magnetTimer = 0.0f;
|
||||
|
||||
private bool killedByShark = false;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
@@ -148,8 +150,11 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
void FixedUpdate()
|
||||
{
|
||||
// Foce reset the rotation.
|
||||
transform.rotation = Quaternion.identity;
|
||||
|
||||
if (damageTimer > 0.0f)
|
||||
{
|
||||
damageTimer -= Time.fixedDeltaTime;
|
||||
@@ -233,6 +238,12 @@ public class Player : MonoBehaviour
|
||||
gameOver = false; // Reset gameOver to prevent multiple coroutine starts
|
||||
}
|
||||
|
||||
if (killedByShark)
|
||||
{
|
||||
killedByShark = false; // Reset the flag to prevent multiple sound plays.
|
||||
StartCoroutine(Revive());
|
||||
}
|
||||
|
||||
if (magnetTimer > 0.0f)
|
||||
{
|
||||
magnetTimer -= Time.deltaTime;
|
||||
@@ -275,6 +286,29 @@ public class Player : MonoBehaviour
|
||||
return false;
|
||||
}
|
||||
|
||||
private IEnumerator Revive()
|
||||
{
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
if (lives > 0)
|
||||
{
|
||||
audioSource.PlayOneShot(killed);
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
canFire = true;
|
||||
exploding = false;
|
||||
gunAnimator.SetTrigger("revived");
|
||||
|
||||
SpriteRenderer[] renderers = GetComponentsInChildren<SpriteRenderer>();
|
||||
foreach (SpriteRenderer renderer in renderers)
|
||||
{
|
||||
renderer.enabled = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gameOver = true;
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator EndGame()
|
||||
{
|
||||
musicManager.pauseMusic();
|
||||
@@ -455,4 +489,23 @@ public class Player : MonoBehaviour
|
||||
|
||||
canFire = true; // Allow firing again after bar hit
|
||||
}
|
||||
|
||||
void OnCollisionEnter2D(Collision2D collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Shark"))
|
||||
{
|
||||
if (exploding)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
killedByShark = true;
|
||||
lives--;
|
||||
Explode();
|
||||
}
|
||||
else
|
||||
{
|
||||
Physics2D.IgnoreCollision(collision.collider, GetComponent<Collider2D>(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user