Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RemiK · Apr 08, 2010 at 01:03 PM · buttonmouserotatelookhold

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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 :)

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image burnumd · May 03, 2010 at 10:57 PM 0
Share

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.

avatar image Adam D. · May 03, 2010 at 11:19 PM 0
Share

Touch good sir.

avatar image Adam D. · May 03, 2010 at 11:22 PM 0
Share

@burnumd - I edited my original to reflect the preferred method. Thanks for the catch!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges