- Home /
Spotlight help
THIS IS NOT OFF TOPIC AT ALL DON'T CLOSE! Can someone give me a script so when you press mouse 1 the spotlight disappears, and when you let go of mouse 1 the spotlight comes back.
The words "Can someone give me a script" is the reason your topic was closed. This site is NOT for giving you free scripts. This site is for helping you with a specific problem. See this for more details.
Also the words "THIS IS NOT OFF TOPIC AT ALL DON'T CLOSE!" is just begging for someone to close it (someone not me because I don't have the authority)
Try asking for instructions, rather than a script. You will get a more positive result.
Answer by SilverTabby · Aug 23, 2011 at 04:33 AM
Try this:
You have a problem. Break it down into smaller problems:
- In Update,
- If mouse1 is down,
Then turn off the spotlight
- Else,
Turn it on.
- If mouse1 is down,
How do I check mouse1? Input.GetButton.
How do I get the spotlight in the script? var spotlight : GameObject;
How do I turn it off? spotlight.[SendMessage][2]("turnOff");
And then have a script that receives the message and turns off the light.
How do I turn it on? repeat above step with "turnOn". Or better yet, create a method that does both and uses a Boolean to determine on/off.
Use this technique and complex problems become simple.
[2]: http://unity3d.com/support/documentation/ScriptReference/Component.SendMessage.html