1

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?

4
  • 1
    Questions of this type, that deal with Unity and JavaScript really belong on Stackoverflow. I have already flagged this question for migration. Commented Jan 16, 2015 at 16:40
  • What errors is the compiler giving? Commented Jan 16, 2015 at 22:44
  • 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. Commented Jan 16, 2015 at 22:55
  • also, you should tag things with Unity. Unity javascript isn't really standard javascript. Commented Jan 16, 2015 at 22:56

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Now I got 2 more errors: "Assets/GameAssets/Scripts/Flashlight.js(13,29): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Type, UnityEngine.Vector3, UnityEngine.Quaternion)' was found." and "Assets/GameAssets/Scripts/Flashlight.js(9,24): BCE0023: No appropriate version of 'UnityEngine.Object.Destroy' for the argument list '(System.Type)' was found." I really don't see the problem, I checked 5 times for syntax errors and for misspellings but I can't find anything.
Both of those errors are because Flashlight is a Type, not an Object. You can't Instantiate or Destroy a Type, you need an actual instance.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.