So here is my timer script that works fine. I need it to activate the game over(UI image ) when the timer reaches 0.I tried attaching a game over script to the UI image ( GOS script)….. no luck
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Timer : MonoBehaviour { public Text gametimer; public float timeLeft; public GameObject Gameover; public Text gameovertext;
// Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (timeLeft > 0) { timeLeft -= Time.deltaTime; } else { timeLeft = 0; } displaytime(timeLeft); } void displaytime(float timeToDisplay) { if (timeToDisplay < 0) { timeToDisplay = 0; Debug.Log("Game Ova YOung!!!"); } float minutes = Mathf.FloorToInt(timeToDisplay / 60); float seconds = Mathf.FloorToInt(timeToDisplay % 60); gametimer.text = string.Format("{0:00}:{1:00}", minutes, seconds); } }
//////// Game over screen script below
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GOS : MonoBehaviour { GameObject GameOverScreen; public Timer timer;
// Start is called before the first frame update void Start() { timer = GetComponent<Timer>(); GameOverScreen.SetActive(false); } // Update is called once per frame void Update()
{ if (timer = null) { GameOverScreen.SetActive(true); }
}
}
The post I need a game over(UI image) to appear after timer reaches 0 appeared first on 100% Private Proxies - Fast, Anonymous, Quality, Unlimited USA Private Proxy!.