Tuesday, September 15, 2015

Click to find the hit object RaycastHit unity

iklan
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);
                    }
                }
            }
            
            
        }
        
        
    }



Click to find the hit object RaycastHit unity
4/ 5
Oleh