Hey guys, need a little help with something. My scene consists of 4 spheres, and what I’m trying to achieve is when you click on one sphere, the colour of the sphere changes, and as you drag the mouse (while it’s still held down) onto the other spheres, the other spheres change colour too. So far what I’ve managed to do is change the colour of the sphere when it’s clicked, but I’m not able to change the colour of the other spheres when I drag the mouse onto them. I assume this is obviously because the code is only run when the mouse is first clicked. Is there a way to change this so a sphere changes colour when the mouse is clicked and dragged onto it? I’ve tried playing around with OnMouseDrag but with no success. Here’s a link to a video of what I’ve got so far and what I’m trying to go for: (Unity) Trying to trigger multiple objects by holding down the mouse with OnMouseDown - YouTube
(All spheres have the same script attached)
And here’s my code:
public GameObject sphere;
public Material material;
void OnMouseDown()
{
sphere.GetComponent<MeshRenderer>().material = material;
}