x


Projector Toggling - Scripting Problem

I am currently running into a scripting problem in my game when trying to toggle a projector on and off. While my game is running, I can toggle the projector off but not on again afterwards. If I turn on the projector manually while the game is running (via the inspector) I can turn it off again, but still not on afterwards. Here is the Java script that I have:

    var projector : Projector;
function Update()
    {
        if(Input.GetButtonDown("Fire2"))
        {
            projector.gameObject.active = !projector.gameObject.active;
        }
    }

Any help on fixing this problem is greatly appreciated.

more ▼

asked Dec 21 '10 at 05:31 AM

JonW gravatar image

JonW
3 1 1 4

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

1 answer: sort voted first

You want to toggle the projector component's enabled status instead of disabing the gameobject the script is probably on:

projector.enabled = !projector.enabled;
more ▼

answered Dec 21 '10 at 05:39 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

Thanks, this fixed it perfectly. I had tried using 'enabled' as opposed to 'active' before but i left the '.gameObject' portion in. Looks like all I had to do was take that part out.

Dec 21 '10 at 05:52 AM JonW
(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:

x5059
x662
x159
x109

asked: Dec 21 '10 at 05:31 AM

Seen: 1198 times

Last Updated: Dec 21 '10 at 05:31 AM