- Home /
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.
Answer by Mike 3 · Dec 21, 2010 at 05:39 AM
You want to toggle the projector component's enabled status instead of disabing the gameobject the script is probably on:
projector.enabled = !projector.enabled;
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.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
No appropriate version of Destroy 3 Answers
C# Script is affecting multiple GameObjects but I would like it to only affect one of them... 1 Answer
How to make gameObject and GUI button invisible/visible? 3 Answers
GUI.Button not showing up 1 Answer