Ray

Selecting a Game Object with a mouse click on it.

February 17, 2014   ·   0 Comments

void Update()
{
    if (Input.GetMouseButtonDown(0))
    {
       Debug.Log("Mouse is down");
 
       RaycastHit hitInfo = new RaycastHit();
       bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
       if (hit) 
       {
         Debug.Log("Hit " + hitInfo.transform.gameObject.name);
         if (hitInfo.transform.gameObject.tag == "item")
         {
          Debug.Log ("It's working!");
         } else {
          Debug.Log ("nopz");
         }
       } else {
         Debug.Log("No hit");
       }
       Debug.Log("Mouse is down");
    } 
}
shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
Unity3D4

Amazon

adsbygoogle

Recent Posts

Categories

Amazon