Answers for "unity if gameobject is clicked"

C#
3

unity check when clicked on object

void Update()
{
  // Check for mouse input
  if (Input.GetMouseButton(0))
  {
  	Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
   	RaycastHit hit;
   	// Casts the ray and get the first game object hit
   	Physics.Raycast(ray, out hit);
   	Debug.Log("This hit at " + hit.point );
  }
}
Posted by: Guest on March-27-2020
0

unity if gameobject is clicked

void OnMouseDown() 
 {
   Debug.Log("Mouse is down")
 } 

 void OnMouseUp() 
 {
   Debug.Log("Mouse is up")
 } 

 void OnMouseClick() 
 {
   Debug.Log("Mouse is clicked (down then up its 1 click)")
 } 

// Works only if the gameobject have a collider
Posted by: Guest on October-29-2020

C# Answers by Framework

Browse Popular Code Answers by Language