I have a code set so if no enemy is killed within a few seconds the game is over it works at first bit after a few sec0nds it doesn’t , so if you don’t kill a enemy the game wont end. I want it set so that if no enemy is killed after few seconds the game will end but its not
I cant find why … so again it works at first but after a few seconds or a few kills it stops working
What I want= I want throughout the entire game setup so that if no enemy is killed and dragged to top of screen every few seconds the game will end
heres code
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class fishdedd : MonoBehaviour {
5.
public AudioClip pop1;
public AudioClip boing;
AudioSource audio;
10.
Animator anim; //reference to the animator component
void Start()
15. {
audio = GetComponent<AudioSource>();
//get reference to the animator component
anim = GetComponent<Animator> ();
20. }
void OnCollisionEnter2D(Collision2D other)
//void OnTriggerEnter2D(Collider2D other)
{
25. */
if (other.gameObject.tag == "topy" || other.gameObject.tag == "Wall" )
{
// do something when we collide with "enemy1" OR "enemy2"
anim.Play("fishded");
30. anim.SetTrigger("Die");
GetComponent<AudioSource> ().Play ();
audio.PlayOneShot(pop1, 0.7F);
DeathWatch.ReportDeath ();
//ScoreManager.score += scoreValue;
35. }
else if (other.gameObject.tag == "shark" || other.gameObject.tag == "shark" )
{
// do something else when we collide with "enemy3" OR "enemy4"
anim.Play("fishded");
40. anim.SetTrigger("Die");
GetComponent<AudioSource> ().Play ();
audio.PlayOneShot(boing, 0.7F);
DeathWatch.ReportDeath ();
}
45.
}
}
50.
}
}
}
*/
here s deathwatch code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeathWatch : MonoBehaviour {
public AudioClip pop1;
public AudioClip boing;
AudioSource audio;
Animator anim;
private const float DeathTimeLimit = 33;
private static float DeathCountdown = DeathTimeLimit;
void Start()
{
audio = GetComponent<AudioSource>();
//get reference to the animator component
anim = GetComponent<Animator> ();
}
private void Update() {
DeathCountdown -= Time.deltaTime;
if (DeathCountdown < 0) {
GameOver ();
anim.Play("fishded");
anim.SetTrigger("Die");
audio.PlayOneShot(pop1, 0.7F);
// Game over
}
}
private void GameOver()
{
Application.LoadLevel("Menu");
}
public static void ReportDeath() {
DeathCountdown = DeathTimeLimit;
}
}