Probaly worst script ever, but can you fix this please?

So yeah, before you start laughing , I have some Lua Expierience but thats it.
Im trying to make a chopper with a spotlight on it (Like from the police ^^).
Now it should change its range from 0 to 150 , but that doesnt happend.
Here’s the code.

function Update () {
	if(Input.GetButton("L")) {
	light.range = 150;
	}
}

Hmm…

How bout this:

function Update () {
	if(Input.GetButtonDown("l")) {
	light.range = 150 - light.range;
	}
}

Oh, and its lower case L… not capitol. :wink:

Nope :o

what is your full code? Can you post it?

Specifically, your var light. How do you declare it?

You would probably have better luck capturing the key instead of a named (ie “fire” or “jump”) button. Try

if (Input.GetKeyDown (KeyCode.L)) {

light is a GameObject reference to the Light component.

In this case it wont much matter how he gets the key, he has other problems.

First, test the light. Put your game object next to a wall or something so that you can see the 150 range on the light to begin with. Then attach this code:

function Update () {
	if(Input.GetButtonDown(KeyCode.L)) {
		print(light);
		light.range = 100;
	}
}

When you run it, and press the L key, then the lights range should drop to 100 and it should print out something.

If neither happens, then your not attaching the script to the light game object. :wink:

:U

Assets/SpotBehaivior.js(2,31): BCE0017: The best overload for the method ‘UnityEngine.Input.GetButtonDown(String)’ is not compatible with the argument list ‘(UnityEngine.KeyCode)’.

Oh… lol

function Update () {
	if(Input.GetKeyDown(KeyCode.L)) {
		print(light);
		light.range = 100;
	}
}

It doesnt prints…
:confused:

And finally… just stick this on any game object…

function Update () {
	if(Input.GetKeyDown(KeyCode.L)) {
		print("Hello");
	}
}

If it does not work, you need to go back and read the fundamentals of how Unity and Unity Scripts work.