- Home /
How to change overlay with timer?
I made a timer script for a camera to turn off after a certain amount of time. I also have an picture as overlay that has to represent the battery. But is there a way that I can change the overlay when it's at 30, 20 and 10 seconds so it looks like the battery is actually draining?
This is my javascript: var timer : float = 30.0; var sound: AudioClip; var camera1 : Camera; var camera2 : Camera;
var CameraSwitch : CameraSwitch;
function Awake(){
CameraSwitch = GameObject.Find("camHolder").GetComponent("CameraSwitch");
}
function Update()
{
timer -= Time.deltaTime;
if(timer <= 0)
{
timer = 0;
audio.PlayOneShot(sound);
camera1.gameObject.SetActive(true);
camera2.gameObject.SetActive(false);
CameraSwitch.Playsound();
}
}
function OnGUI()
{
GUI.Box(new Rect(155, 100, 75, 23), "Battery: " + timer.ToString("0"));
}
Comment
Your answer
Follow this Question
Related Questions
Trouble with Time.Timescale 2 Answers
Change Position of an object 1 Answer
Camera switch after specific time 1 Answer
[JS] Custom camera rotation resets on Var change? 0 Answers
Switching cameras (JavaScript) 0 Answers