Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity know when gameobject presed

void Update () {
         if (Input.GetMouseButtonDown(0)) {
             CastRay();
         }       
     }

     void CastRay() {
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit2D hit = Physics2D.Raycast (ray.origin, ray.direction, Mathf.Infinity);
         if (hit.collider !=null) {
             Debug.Log (hit.collider.gameObject.name);
     }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #unity #gameobject #presed
ADD COMMENT
Topic
Name
6+9 =