I am working on a script where i have a spot light attached to a flashlight object, and i want to cut it on or off with the " o " button. i tried several different ways, until i searched the forums and found a method that i thought would work.( 1st commented block of code) the problem with that block of code is that it turns on or off all lights, and i just want to be able to toggle only the flashlight. i got it to work by using 2 different letters (o and p, as in the 2nd commented block of code, but that is not how i want it to work. anyway i tried a combination of the 2 commented blocks of code and i don’t get any errors, but when i start the scene, the light is on, then when i press o the light goes off. but, when i press o again to turn it on, nothing happens except the console says " the light is off" which tells me that it is not returning to the start of the code… i am stuck now… below is the code and the several other attempts that i tried. i’m still learning with difficulty…
thanks
// public var lightOnOff = light.intensity;
public var lightOnOff : boolean = true;
function OnGUI()
{
GUI.Label (Rect (10, 10, 200, 20), "Use o to turn flashlight on or off");
}
function Update()
{
if(Input.GetKeyDown("o"))
{
if(lightOnOff == false)
{
light.intensity = lightOn;
Debug.Log("Light is on");
}
else
light.intensity = lightOff;
Debug.Log("light is off");
}
}
/*
function Update () {
if(Input.GetKeyDown("o"))
{
if(GetComponent(Light).enabled == false)
{
GetComponent(Light).enabled = true;
Debug.Log("light on");
}
else
GetComponent(Light).enabled = false;
Debug.Log("light off");
}
}
*/
/*
function Update()
{
if (Input.GetKeyDown("o"))
{
light.intensity = lightOn;
}
if(Input.GetKeyDown("p"))
{
light.intensity = lightOff;
}
}
*/
/*
function Update ()
{
if (Input.GetKeyDown("o")) (lightOff == true)
{
light.intensity = lightOn;
//lightOn;
}
}
*/
/*
if(lightOnOff == 0)
{
if (Input.GetKeyDown("o"))
{
lightOn;
}
else
{
lightOff;
}
*/
/*
if(Input.GetKeyDown("o"))
{
light.intensity = lightOn;
}
if(Input.GetKeyDown("o"))
{
light.intensity = lightOff;
}
*/