- Home /
2D Game Mouse Problem
Hello guys, i'm making a 2D game, and i got a mouse problem. first, see the script below. it's enemy's script.
void OnMouseDrag() { Hp-=5; } void Update() { if(Hp<=0) Destroy(gameObject); }
This means when my mouse position is inside of enemy's box collider 2d(i'm making 2d game) and if i'm pressing mouse button, then enemy hp is going to be decreased until i stop pressing button, right? so let's say mouse is inside of enemy's collider and i'm pressing mouse button. after some time has passed, hp is less then 0, so object has been destroyed. after that, with mouse button steel pressing(i mean steel firing), move my mouse pointer to another enemy's collider. but second enemy got no damage until i detach my finger and re-press button. what should i do in this situation?
sorry for low level English, i'm not a English-speaking country's people. so please use easy words and if you can.. excepting you guys help.
Your answer
Follow this Question
Related Questions
Why is OnDrag triggering but not OnMouseDown? 0 Answers
How to detect when the mouse button is being held down while the cursor is inside a collider? 1 Answer
why the unity3d's OnMouseDown method lose efficacy sometime? 0 Answers
OnMouseDown won't work on a simple button 2 Answers
How to make different actions using OnMouseDrag with two different colliders on one Game Object. 0 Answers