- Home /
Is There An OnMouseStop?
Ok let me try to explain this as simply as possible.
When the player clicks, a pivot point from where he clicked is made, this pivot point will be the position of the mouse cursors 'x' position at the time it was pressed.
if (Input.GetMouseButtonDown(0)) {
mPos_1 = Input.mousePosition.x;
}
From then on, the mouse cursors 'x' position will be recorded and compared to the pivot point. This will rotate the player.
mPos_2 = Input.mousePosition.x;
rotationSpeed = 2 * (mPos_2 - mPos_1);
if (rotationSpeed > 25) { rotationSpeed = 25; }
if (rotationSpeed < - 25) { rotationSpeed = - 25; }
myTransform.Rotate (0, rotationSpeed * Time.deltaTime, 0);
I need to know when the mouse has stopped moving so our player does not continue to rotate.
Thanks for reading! I would like to ask for the simplest possible way of achieving this.
Cheers!
Mithos
you have to keep the previous position.
look at the new position
if they are the same ... the mouse has not moved.
In "Objective - c" you can apply something called a "watcher" to a float value.
The watcher sees the number changing and also if the number has stopped.
Do we have something like that in c#?
i have no idea, because I hate computer languages.
It sounds like you are an advanced programmer .. as you can see, you simply have to program it in a stateful manner.
(ie, "you need a variable")
it is an incredibly simple situation.
to be honest i'd just use a variable every time when program$$anonymous$$g interface so it's "if nowPosition != previousPosition"
you see that in every bit of code relating to handling mouse, touch movement
I've certainly programmed this an awfully, awfully lot in XCode and I've never felt it would be a good idea to use a watcher there. so to be honest i'd give it a miss here, even if UnityScript has a watcher concept. To find out if U/S has a watcher concept, ask a new question and some expert here will know.
you may enjoy this article-lenth answer on unity interface
http://answers.unity3d.com/questions/292333/how-to-calculate-swipe-speed-on-ios.html
pls vote up if enjoyable :) nobody votes that answer up, I don't believe it! ;)
Ok Fattie! +1
Im so used to using watchers thats all.
I found unity didn't have one and was like wut?
So yeah! Thanks a bunch for being the usual incredibly helpful forum guy!
Cheers ^^
$$anonymous$$ithos