Tuesday, 15 September 2015

Click to find the hit object RaycastHit unity

using UnityEngine;
using System.Collections;
    
    public class ClickScript : MonoBehaviour {
        
        void Update () 
        {
            Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
            RaycastHit hit;
            if (Input.GetButtonDown ("Fire2")) 
            {
                if (Physics.Raycast(rayout hit100))
                {
                Debug.Log("hit.tranform = "+hit.transform);
                    if (hit.collider.CompareTag("a"))
                    {
                        //Debug.Log("hit.tranform = "+hit.transform);
                        //Debug.Log("hit.tranform = "+hit.transform.tag);
                    }
                    
                    else
                    {
                        //Debug.Log("hit.point = "+hit.point);
                    }
                }
            }
            
            
        }
        
        
    }



No comments:

Post a Comment