- Home /
Look around when holding down mousebutton
Hi! I'm new with Unity, and I'm a noob at scripting.
What I want to do is to make the player able to look around when pressing the mouse button. And the speed of rotating is in relative to the senter of where the mouse was when pressing.
The player can walk around with the simple FPSwalker-script. But I want the mouse to be visible at all times, and be able to move the mouse freely (and click objects) while walking. But as soon as the player presses and hold the mousebutton down, they can look around. The speed inceases as the player move further away from where he pressed the mouse.
I probably need some sort of delay to differentiate between clicking or pressing, or maybe Unity have that already...
My engelish isn't as good as it should be, but I hope you understand what I want.
Answer by Adam D. · May 03, 2010 at 10:30 PM
Just wrap the current code in the MouseLook.cs script (just the code in the Update function) with...
if(Input.GetButton ("Fire1")){
//Current code goes here...
}
This will make sure the left mouse button is held down. Other mouse buttons can be mapped like so: http://unity3d.com/support/documentation/ScriptReference/Input.GetMouseButton.html
** I edited my answer to the preferred method, as commented below :)
The preferred method of getting that condition is to use 'if (Input.GetButton ("Fire1")) { //... }' or "Fire2" for the second mouse button or "Fire3" for the middle mouse button (using the default input settings). That way, if the user has switched the primary mouse button, you're covered. Gotta watch out for those southpaws.
@burnumd - I edited my original to reflect the preferred method. Thanks for the catch!
Your answer
Follow this Question
Related Questions
Mouse look/rotate 2 Answers
GUI Button Question 1 Answer
Movement along X and Z axis... 2 Answers
Look at mouse 1 Answer
Button being pressed but an other button gets the effect. 0 Answers