- Home /
 
               Question by 
               nabajit_ · Aug 27, 2017 at 02:46 PM · 
                unity 5javascriptraycast  
              
 
              Why UI layer is being ignored by the raycast?
In my scene the character moves to the mouse position on left mouse click if we have clicked on the ground. I use raycast to determine if we clicked on a object on which we can move. I have all objects on which we can move in one layer named ground and all UI buttons in UI layer. I don't want my character to move when we click on UI button. But the raycast ignores the UI layer.
SCRIPT (in UnityScript) :
 var navMeshAgent:AI.NavMeshAgent;
 var mask:LayerMask;
 function Start(){
     navMeshAgent = GetComponent.<AI.NavMeshAgent>();
 }
 function Update () {
       if(Input.GetMouseButton(0)){
         var ray:Ray = cam.ScreenPointToRay(Input.mousePosition);                  
         var hitInfo:RaycastHit;
         if(Physics.Raycast(ray,hitInfo,100,mask)){ //I think I have to set one more condition here to check if we have clicked a button
            navMeshAgent.SetDestination(hitInfo.point);
      }
    }
  }
  function click(){ //This function is called on clicking a button
       //do something
  }
The LayerMask variable mask set to consider both UI and ground layer and ignore other layers.
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Switch GameObjects Tags with javascript 1 Answer
Raycast Pause Between Hits? 0 Answers
Raycast Tag of Hit GameObject 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                