Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Why UI layer is being ignored by the raycast?

$
0
0
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.(); } 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.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>