I am trying to make a light turn off when i press w (“Forward”) but it just doesnt work.
Update I fixed that.
How would I make a script that would turn the light off from a diffrent object ? like if i had a script connected to another. I use the following to turn off this light with script on the light but how would i do diffrent to do ass mentioned above.
function Update () {
if(Input.GetButtonDown("Forward")){
light.enabled = false;
}
}
What you mean with " from a diffrent object"? Player turns off light, or what?
- You can call for function on other object!
like I dont get the light.enabled function I can only get it to work when it is connected to a light =/ Do I have to make a seperate script for the lights that has like a variable or something telling it if true or false turn off or on and change that variable with the other objects script or something ?
For example I want to use a switch and that switch turns off a certain light for example.
1.Yes you can make a seperate script(and call to turn it on/off)
2. If you want only once turn it off(and without possibility to turn on light - later), you can destroy object!
how XD what script to activate from a seperate script?
var light : Light; // Will be shown in inspector for you to assign
function Update () {
if (Input.GetButtonDown ("Forward")) { // If "Forward" button is pressed
light.enabled = !light.enabled; // Switch the light
}
}
If you don’t like to assign things through the inspector:
function Start () {
light = GameObject.Find ("NameOfMyLight").light;
}