Question by
sid4 · Aug 02, 2017 at 10:20 PM ·
scripting problemcollisioncollision2dgameover
i want game to end on no collisions
I cant get the game to end if no enemy's are killed every 4 seconds. I tried adjusting this script below but cant figure it out. ive been trying for weeks if not over a month please help
I have some more references in other scripts to this one
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 < 2) {
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;
}
}
Comment