1
votes

I recently started making a new game and I'm kinda an amateur coder.

var FlashlightOn : boolean = true;

function Update () {
    ButtonClicket();
}

function ButtonClicket () {
    if (Input.GetButton("Flashlight")) && FlashlightOn == true {
        Destroy(Flahslight);
        FlashlightOn = false;
    }
    else
    {
        Instantiate (Flashlight, Vector3(i * 0, 0, 0), Quaternion.identity);
        FlashlightOn = true;
    }
}

In the compiler error part it says I need to put brackets at the end and some other junk that doesn't need to be done. What am I doing wrong here?

1
Questions of this type, that deal with Unity and JavaScript really belong on Stackoverflow. I have already flagged this question for migration. - Security Hound
What errors is the compiler giving? - Adam H
Maybe its different in Unity and people here can correct me, but in standard javascript there's a very important convention that all functions are written in camelCase (start with a lowercase letter), unless you intend for the function to be used with the new keyword. - George Mauer
also, you should tag things with Unity. Unity javascript isn't really standard javascript. - George Mauer

1 Answers

2
votes

Having run the code through the compiler myself, the errors it's giving are valid. Your code simply has a syntax problem and a typo:

if (Input.GetButton("Flashlight") && FlashlightOn == true) {

The close parenthesis for the if statement was in the wrong place.

Destroy(Flashlight);

You misspelled 'Flashlight'.

Also, i isn't defined isn't this code snippet, which is fine if it's a global variable, but you may want to double check it.