Answers for "unity select object with mouse"

C#
0

unity select object with mouse

void Update() {
	if (Input.GetMouseButtonDown(0)) {
		RaycastHit hitInfo = new RaycastHit();
      	bool hit = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
        if (hit) {
          	// any object hit
        	Debug.Log("Hit " + hitInfo.transform.gameObject.name);
          
          	// filter with tag name
          	if (hitInfo.transform.gameObject.tag == "TagName") {
            	// do something..
            }
        }
    }
}
Posted by: Guest on July-01-2021

C# Answers by Framework

Browse Popular Code Answers by Language