x


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.

more ▼

asked Aug 19 '12 at 07:50 PM

SWFlyerUK gravatar image

SWFlyerUK
1 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

If bluelight is an emty game object with light component attached to it try with:

bluelight.light.enabled = true;
more ▼

answered Aug 19 '12 at 09:40 PM

tigerfoot gravatar image

tigerfoot
108 1 3 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3695
x2090
x427
x216
x135

asked: Aug 19 '12 at 07:50 PM

Seen: 762 times

Last Updated: Aug 19 '12 at 09:40 PM