Raycast Tag hit not working

Hello everyone

So i have my little script for a raycast and it should play an animation when it hits the labyrinth in a specific range

#pragma strict

function Update() {
	var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
	var hit : RaycastHit;
	if (Physics.Raycast (ray, hit, 100)) 
		Debug.DrawLine (ray.origin, hit.point);
		if(hit.transform.gameObject.tag == ("Labyrinth"))

i tagged the labyrinth right and i dont become any errors if anyone could help that would be great :smiley:

thanks in advance skullbeats1

The code is correct (to make sure I tried it in an empty scene with a camera and a sphere), so I see 4 possible reasons it’s not working for you:

  1. the labyrinth GameObject has no collider attached (or too may be too small) or it’s in the layer “Ignore Raycast”
  2. it’s hitting another collider that is located between the camera and the labyrinth object
  3. the labyrinth hasn’t the tag “Labyrinth” (the letter case must be exact)
  4. the script where this code lies is disabled