Seperate Input.GetMouseButton(0) between multiple objects

I have multiple wheels that I want to be able to click and rotate individually. I have the script to rotate them by using Raycast and I have the input for the mouse click. However, if I have the script on two objects when I click the mouse on one object and rotate it, it will rotate both objects. I want it to only rotate the object I am actually clicking on.

Any thoughts?

You need a MouseInputManager class that can then dispatch inputs where they need to go.

Easiest is to do it by SendMessage : send the click message to the object hit by the raycast.

Fancier but C# only is to use events (see prime31’s excellent video tutorials on youtube. First one is about events and delegates, here)

Another solution would be to use NGUI : it’s event system is solid. You could then just add the following to your scripts :

function OnClick()
{
     Debug.Log("this script's gameObject has been clicked");
}