- Home /
OnMouse event only works for a moment and then not working
I made a randomly walking NPC with NavMesh system and I wanted to interact with that NPC by mouse event. So I used OnMouseEnter events on it.
After I play the scene, OnMouse events works perfectly. However, it ceases to work after certain time (about 3 seconds) and does not respond to mouse events. Why is this happening? I'm using Unity 2019.4.19f1 version.
Below is link of my project package. https://drive.google.com/file/d/1wdtONaAxPrGF8GIlKDkR97bttxMxB4bw/view?usp=sharing
Answer by Devster2020 · Jun 30, 2021 at 08:45 AM
Hello @ahnjinmo
Looking to your image attached, OnMouseEnter and OnMouseExit are called 4 times, so they respond to the inputs.. in the Console, you have "Collapse" enabled, that unify all text that are equals, so you see them only one time..
If the player don't do what you expect, I think there are errors in other scripts.
I know what you said. I cut out the gif due to size of it. You can see the whole video in this link below. As you see this, you can see that it does not respond after 4 times. https://drive.google.com/file/d/1tepbNk7we9uWmNMmUed_6I6oDTVWH3qG/view?usp=sharing
Ok .. from what I see, the problem does not come from the passage of time, but from the fact that the character moves. From the moment he changes position, he is no longer "hit" by the mouse .. is it possible that in the script that makes the character walk, you have disabled his collider thus preventing you from triggering the action again?
I guess it's just a coincidence because it responds well though it's moving as I experimented several times. Also I tried disabling him walk and stay still, but it resulted the same... It did not respond to mouse event after about 3 seconds.. so I guess the problem is something else.. :(
You could check if your EvenSystem gets destroyed or disabled.
Yes, this may be an additional problem that has occurred.
I figured out that as I remove the RigidBody component of NPC, it responds normally. Hmm.. I wonder why rigidbody component causes this.