How to make RayCast Detect a Tag?

var hit : RaycastHit;

function Update() {
   if (Physics.Raycast (transform.position, transform.forward, hit, 10)) && hit.collider.gameObject.CompareTag("Player") }
   {
print ("detected!");


else print ("nothing..");

}

I get a bunch of errors and I have been stuck on this for awhile now…

There are mismatched parenthesis and curly brackets in lines 5 and 6 of your code. Take a look at the fixed code below, and compare to yours to see what I’m talking about (the line numbers probably won’t be the same):

var hit : RaycastHit;

function Update() {
    if (Physics.Raycast (transform.position, transform.forward, hit, 10) && hit.collider.gameObject.CompareTag("Player")){
        print ("detected!");
    } 
    else {
        print ("nothing..");
    }
}

Thanks A lot! :smiley: