Unexpected Token (63190)

Error:

Assets/Scripts/ButtonPush.js(6,48): BCE0043: Unexpected token: &&.

Script:

var ButtonDown : AnimationClip;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;

function Update () {
 
if (Physics.Raycast (ray, hit, 100)) {
if ( hit.collider.gameObject.name == "Button") && (Input.GetMouseButtonDown(0)) {

animation.Play("ButtonDown");

audio.Play();

		}
	}
}

Question:

Why?

1 Answer

1

if (( hit.collider.gameObject.name == “Button”) && (Input.GetMouseButtonDown(0)))

You need more ()

As it was, the && was ‘outside’ the condition, and the second one was just left hanging.

Actually better:

if ( hit.collider.gameObject.name == “Button” && Input.GetMouseButtonDown(0))

Perfect... But I am getting this error now: get_main can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. I don't even have a start function.

I have no idea. Best this was a new question, post the whole script.

Never mind, I got the script to work.