#pragma strict
var timer : float = 10.0;
var lsCanvas : Canvas;
function Start () {
timer -= Time.deltaTime;
if(timer <= 0)
{
timer = 0;
lsCanvas.enabled = true;
}
}
What´s wrong with this script?
#pragma strict
var timer : float = 10.0;
var lsCanvas : Canvas;
function Start () {
timer -= Time.deltaTime;
if(timer <= 0)
{
timer = 0;
lsCanvas.enabled = true;
}
}
What´s wrong with this script?
The Start function is called when an object is enabled, Time.deltaTime is the time between frames. If your timer is 10 and start is called once, in the frame when the GameObject is enabled, then your if statement will always result in false and lsCanvas.enabled is never be set. Did you mean to put this in the Update function which is called every frame?
If you did mean to put it in Update, you should also constrain the overall process with a boolean so it’s not evaluated over and over again
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Timer : MonoBehaviour {
public Canvas canvasOne;
IEnumerator Start () {
canvasOne.gameObject.SetActive(false);
yield return new WaitForSeconds(10f);
canvasOne.gameObject.SetActive(true);
}
}