Pardon my badly written script. I am new to scripting.
I am trying to make a simple game where you run around and shoot the “dummies”. I want to put into my code that when all of the dummies have been shot, then my timer will stop, however all i can get it to do is stop when i only destroy one of them. The way I have tried to do it is when one of the dummies have been destroyed, then count up 1. all the way up to 16(the amount of dummies). I am not stuck on this counting up method if you have another way of doing this. If someone could post on here and help me out, I would greatly appreciate it.
Here are my script for it… (again please excuse the sloppyness :D)
using UnityEngine;
using System.Collections;
public class Timer2 : MonoBehaviour {
public float startTime;
private float elapsedTime;
public float dummiesDead = 15;
public GameObject dummy1;
public GameObject dummy2;
public GameObject dummy3;
public GameObject dummy4;
public GameObject dummy5;
public GameObject dummy6;
public GameObject dummy7;
public GameObject dummy8;
public GameObject dummy9;
public GameObject dummy10;
public GameObject dummy11;
public GameObject dummy12;
public GameObject dummy13;
public GameObject dummy14;
public GameObject dummy15;
public GameObject dummy16;
//TimerGUI
public GUIStyle myStyle;
public Rect rect = new Rect(300, 25, 100, 200);
void Awake(){
startTime = 0;
}
void Update () {
if (startTime > 0)
{
elapsedTime = Time.time - startTime;
}
if( dummy1 == null){
dummiesDead = +1;
}
if( dummy2 == null){
dummiesDead = +1;
}
if( dummy3 == null){
dummiesDead = +1;
}
if( dummy4 == null){
dummiesDead = +1;
}
if( dummy5 == null){
dummiesDead = +1;
}
if( dummy6 == null){
dummiesDead = +1;
}
if( dummy7 == null){
dummiesDead = +1;
}
if( dummy8 == null){
dummiesDead = +1;
}
if( dummy9 == null){
dummiesDead = +1;
}
if( dummy10 == null){
dummiesDead = +1;
}
if( dummy11 == null){
dummiesDead = +1;
}
if( dummy12 == null){
dummiesDead = +1;
}
if( dummy13 == null){
dummiesDead = +1;
}
if( dummy14 == null){
dummiesDead = +1;
}
if( dummy15 == null){
dummiesDead = +1;
}
if( dummy16 == null){
dummiesDead = +1;
}
if (dummiesDead == 16f) {
startTime = 0;
}
}
void OnTriggerEnter(){
startTime = Time.time;
}
void OnGUI(){
GUI.Label( rect , (elapsedTime.ToString("F2")),myStyle);
rect.x = 20f;
rect.y = 20f;
}
}