Posts

Showing posts with the label ray

casting rays, layer masks, filter objects

 An edit if you will.. When casting rays with masks/filters, remember the ray will keep going until it hits something...so if you have some junk under your floor geo, it's likely the ray will hit it. So be sure to have a function that checks the hit object somewhere..   Some code -                  LayerMask mask = LayerMask.GetMask("spawnObject");                          Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //cast ray             RaycastHit hit; //create hit event variable             if (Physics.Raycast(ray, out hit,50f,mask)) //if ray hits object             {           ...

"on click" basics

From the Unity pages, a simple way to detect your mouse clicks - using UnityEngine; using System.Collections; // Detects clicks from the mouse and prints a message // depending on the click detected. public class ExampleClass : MonoBehaviour { void Update () { if ( Input.GetMouseButtonDown (0)) Debug.Log ("Pressed primary button."); if ( Input.GetMouseButtonDown (1)) Debug.Log ("Pressed secondary button."); if ( Input.GetMouseButtonDown (2)) Debug.Log ("Pressed middle click."); } }    And from this site - void Update ( ) { if ( Input . GetMouseButtonDown ( 0 ) )        {      Ray ray = Camera . main . ScreenPointToRay ( Input . mousePosition ) ;      RaycastHit hit ;      if ( Physics . Raycast ( ray , out hit ) )             {           Destroy ( h...