# Mouse Problem

 0 I've go the following script which rotates an object in front of me as I mouse over it. However, when I lift up on the mouse button, the rotation stops. I would like the function to continue, even when I lift up. How can I do this? Here's the code: ``````var speed : int; var friction : float; var lerpSpeed : float; private var xDeg : float; private var yDeg : float; private var fromRotation : Quaternion; private var toRotation : Quaternion; function Update () { if(Input.GetMouseButton(0)) { xDeg -= Input.GetAxis("Mouse X") * speed * friction; yDeg -= Input.GetAxis("Mouse Y") * speed * friction; fromRotation = transform.rotation; toRotation = Quaternion.Euler(yDeg,xDeg,0); transform.rotation = Quaternion.Lerp(fromRotation,toRotation, Time.deltaTime * lerpSpeed); } } `````` more ▼ asked Jun 23 '11 at 04:44 PM AnimAlu 1 ● 9 ● 10 ● 12 Chris D 2.5k ● 5 ● 7 ● 25 Please remember to format your code (the 10101001 button) :D Jun 23 '11 at 05:03 PM Chris D Thank you Chris! I'm new here :) Jun 23 '11 at 05:04 PM AnimAlu add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 add in a boolean value to see if you've already clicked on it or not. Something like: ``````var activelyRot : Boolean = false; function Update () { if(Input.GetMouseButton(0)) activelyRot = !activelyRot; if(activelyRot){ xDeg -= Input.GetAxis("Mouse X") * speed * friction; yDeg -= Input.GetAxis("Mouse Y") * speed * friction; fromRotation = transform.rotation; toRotation = Quaternion.Euler(yDeg,xDeg,0); transform.rotation = Quaternion.Lerp(fromRotation,toRotation, Time.deltaTime * lerpSpeed); } } ``````This should let you click once to begin controlling it, then click again to stop it. more ▼ answered Jun 23 '11 at 05:07 PM Chris D 2.5k ● 5 ● 7 ● 25 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 Not sure why, but I'm getting a compiling error when I run this. complete code: ``````var speed : int; var friction : float; var lerpSpeed : float; private var xDeg : float; private var yDeg : float; private var fromRotation : Quaternion; private var toRotation : Quaternion; var activelyRot : Boolean = false; function Update () { if(Input.GetMouseButton(0)) activelyRot = !activelyRot; if(activelyRot){ xDeg -= Input.GetAxis("Mouse X") * speed * friction; yDeg -= Input.GetAxis("Mouse Y") * speed * friction; fromRotation = transform.rotation; toRotation = Quaternion.Euler(yDeg,xDeg,0); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed); } } `````` more ▼ answered Jun 23 '11 at 05:32 PM AnimAlu 1 ● 9 ● 10 ● 12 In the future, please try to keep clarifications or feedback attached to the entry you're referring to. You can't comment on my answer yet (a quirk of how the rep system works here) so, in the mean time, just put comments on your question or edit your post.The answer area should be reserved for solutions.In regards to the compile error, I apologize; I'm not somewhere I can test the code at the moment. What error are you receiving? Jun 23 '11 at 05:42 PM Chris D add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x983
x723
x160
x15

asked: Jun 23 '11 at 04:44 PM

Seen: 811 times

Last Updated: Jun 23 '11 at 05:42 PM