- Home /
The OnMouseOver function not working with multiple objects
The OnMouseOver function seems to be not working while there are more than one gameobjects in the scene with the scripts that contain the OnMouseOver function. If I only have one, it will work but when I duplicate the object, they both stopped working.
Here is my code:
IEnumerator OnMouseOver()
{
if(Input.GetMouseButton(1)){
player = GameObject.FindWithTag("Player");
yield return new WaitForSeconds(0.4f);
Move_player();
}
Debug.Log(this.name);
}
I have the collider, there is no hidden colliders. As I said, it was working with only one object but as soon as there is another object that carries this script they all stopped working. Any ideas? Thank you!
Answer by qsp18 · Dec 07, 2020 at 03:43 PM
First, why IEnumerator?
Why not the Unity commmand "OnMouseOver()" https://docs.unity3d.com/2019.3/Documentation/ScriptReference/MonoBehaviour.OnMouseOver.html
Did you Started the Coroutine on each Object?
And if you only check for a click, i would use the UnityCommand: OnMouseDown() https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnMouseDown.html