- Home /
Enable/Disable Game Object With GUI Button
Hi folks,
I'm currently designing a car game and have hit a snag.
I've got several lights, all of the lights are attached to their own, seperate, empty gameobject.
What i'm planning to do, is have the ability for the lights to be switched on/off with the touch of a GUI button, this is for Android. By default, the lights are off.
I've tried a variety of scripts i've made, such as the one below:
var bluelight1: GameObject;
function Start () {
bluelight1 = GameObject.Find("GameObject5");
}
function OnGUI () {
GUI.Box(Rect(100,100,600,400),"");
if(GUI.Button(Rect(120,450,100,20),"Lights On")){
bluelight1.active = true;
}
}
Any ideas on this one please?
Thanks,
SWFlyerUK.
Answer by tigerfoot · Aug 19, 2012 at 09:40 PM
If bluelight is an emty game object with light component attached to it try with:
bluelight.light.enabled = true;
Your answer
Follow this Question
Related Questions
gameobject.setActive(true) || (false) hiccups game for 3 to 5 seconds 4 Answers
Toggling the light with lightmapping(baked and dynamic shadows) 1 Answer
Alternatives to GameObject.SetActive(...) 2 Answers
Gui.Enable transperancy 4 Answers
If you disable a gameobject, does an InvokeRepeating loop end or pause? 3 Answers