Hello,
I’m new to Unity and need some help. What I’m hoping to happen is for a box to show up when the timer reaches 0. For some reason it just wont happen. Here is my script.
var Timer : float = 60;
static var Level1TargetAmounts = 5;
static var gameOver : boolean = false;
function OnGUI ()
{
GUI.Label (Rect (10, 30, 100, 20), Timer.ToString());
GUI.Label (Rect (10, 50, 200, 20), "Amount Of Targets Left : " );
GUI.Label (Rect (160, 50, 100, 20), Level1TargetAmounts.ToString());
if(gameOver.active == true)
{
GUI.Box (Rect (0, 0, Screen.width, Screen.height),"");
}
}
function Update()
{
Timer -= Time.deltaTime;
if (Timer <= 0)
{
Timer = 0;
gameOver = true;
}
}
[ExecuteInEditMode]
public class TimeCountTransition : MonoBehaviour
{
public GUIText timeShow;
public int time;
public Texture2D texture_bg; //after time over
//-----------------initalization of audio-----------------------------------------------------------------------------------------------------
public AudioClip ac_ButtonSound;
public AudioSource audioSource;
public GUIStyle myStyle;
void OnGUI()
{
GUI.Label(new Rect(420,50,100,50),"Time:",myStyle);
timeShow.text = time.ToString();
if(time==5)
{
GUI.Label(new Rect(100,100,450,50),"Your time will be closed with in five seconds",myStyle);
}
if(time==0)
{
GUI.DrawTexture(new Rect(0,0,600,450),texture_bg); //background texture
GUI.Label(new Rect(150,200,300,250),"Your time is over if you want to play again press Restart button",myStyle);
if(GUI.Button(new Rect(200,300,100,50),"Restart"))
{
audioSource.PlayOneShot(ac_ButtonSound);
Application.LoadLevel(Application.loadedLevel);
}
else if(GUI.Button(new Rect(350,300,100,50),"Quit"))
{
audioSource.PlayOneShot(ac_ButtonSound);
Application.LoadLevel("Start");
}
}
}
void Start ()
{
time=60;
InvokeRepeating("Subtract", float.Epsilon, 1);
}
void Subtract()
{
if(time > 0)
{
--time;
}
}
IEnumerator WaitTimeForScreen()
{
yield return new WaitForSeconds(1);
}
}
once tried this one.if you want to time increment you can use ++time it will time increment.