How to detect clicks from other objects in one script?

The basic way to a click is if(Input.GetMouseButtonDown(0)) but how do you detect a click from another object in one script. That way you don’t need to make multiple scripts. Is there actually a way to do that? Thanks, I’m new to Javascript :slight_smile:

Hello markzareal, You can use ray casting to detects the click events
here is the documentation link of ray casting. Raycast

You can detect object by it’s tag or name then ray hit something.

You just want to make one script to detect clicks.

Edited:

Here is some code you can use it’s not tested.

   void Update() {		if(Input.GetMouseButtonDown(0))
	{
		Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		RaycastHit hit;
		if (collider.Raycast(ray, out hit, 100.0F))
		{ 
			if( hit.collider.gameObject.name == "YourGameObjectName")
			{
				//Perform action here.
			}

			//Or use 

			if(hit.collider.CompareTag("YourGameObjectTag"))
			{
				//Perform action here.
			}
		    } 
	    }
    }

void Update () {
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
if (hit.collider.tag==“something”){
//doSomething
}
}
}