- Home /
How to access a gameobject from script?(C#)
I want to make a variable of a gameObject of a scene and access to all his properties and change it.
I want to activate and deactivate a SpotLight, change color, angle, etc, for example, from a script.
Sorry for ask this but is a little confusing and hard to searching it in Scripting Reference.
Answer by Graham-Dunnett · Jul 15, 2013 at 09:54 PM
What's hard about
Visit the scripting reference
Click runtime classes in the menu bar on the left
In your browser do a search for "light"
Follow the link to get to http://docs.unity3d.com/Documentation/ScriptReference/Light.html
Click on "color" to get a small code example that shows how you can change the light colour.
Ditto "spotAngle".
Scroll down the Light page a little to see the
enabled
property, which turns the light on and off.
Just go through the Overview (for your question, it is here), it should help you to understand how Unity scripting works. Also, since I assume you just started to learn Unity, you should take a look at the 3D platform tutorial.
Thanks, was so easy just make a GameObject public variable and drag my SpotLight object to it.
Your answer
Follow this Question
Related Questions
Add Force At Player 0 Answers
Change gameObject within a Transfom 1 Answer
When should I use prefabs? 2 Answers
Very silly and simple javascript question 1 Answer
How to access and change scriptable objects on instantiated prefabs 1 Answer