var : Spotlight ;
function Update () {
if(input.getkeydown.keycode.alpha7))
Light.enable=true ;
}
if(input.getkeydown.keycode.alpha7))
Light.enable= false;
{
I keep getting this error BCE0044: expecting EOF, found ‘var’.
var : Spotlight ;
function Update () {
if(input.getkeydown.keycode.alpha7))
Light.enable=true ;
}
if(input.getkeydown.keycode.alpha7))
Light.enable= false;
{
I keep getting this error BCE0044: expecting EOF, found ‘var’.
You have quite a few mistakes in your script; both in syntax and logic. I think what you want is something like this:
var Spotlight : Light;
function Update()
{
if(Input.GetKeyDown(KeyCode.Alpha7))
{
Spotlight.enabled = !Spotlight.enabled;
}
}
Notice we declare what type the variable Spotlight is, otherwise it won’t be assignable in the inspector. Be careful with your casing, and open/closed parenthesis/brackets:
if ( Input.GetKeyDown ( KeyCode.Alpha7 ) )
not
if ( input.getkeydown.keycode.alpha7 ) )
Regarding the logic: Although you have your second if statement floating outside the Update function, I assume you meant for it to be inside. Think about what will logically happen during execution: You check for a keypress, enable the light if the key has been pressed, then check (during the same Update frame) if that key was pressed again and subsequently disable it. Even without the errors in syntax, this will always end up disabling the light and not really re-enabling it.
Instead, we check for the keypress once for that Update frame, and set the light’s enabled property to whatever it is not. You see how that would work?
If you’re new to programming in Unity I would strongly suggest you start learning C# instead. It may seem more difficult, and in some ways it might be, but in my opinion it’s a much safer and better language to start learning. I think JS has a tendency of letting you get away with alot of things that you might not have intended, and makes debugging very difficult if you don’t know what you’re doing.
Nice post Roland. Good to see helpful people are still around and willing. ![]()
Thank you sir - we all start somewhere, right?
That Einstein quote: Words to live by.
Hello,
Now I realise where I made a few mistakes, thanks for the help it is much appreciated. I am not new to programming.
fixed.
I find it interesting that you were trying to offer ‘your services’ to people in return for putting there game under your name when you cant even write a basic script… not sure what exactly you have to offer.
I can make a basic script.I mostly model , animate and I just wanted to help people. I changed the “services” and I am willing to help anyone with no catch as it seems to suit the public, so I really don’t know what your problem is. I dont really like you either half of your comments on the forums are negetive. I really dont need to explain to you. Get a grip man. Editing the quote so it suits your satisfaction?..pathetic.
The quote was edited to make it more accurate, not to suit my satisfaction.
Ok.