Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 jsquiz82 · Oct 15, 2011 at 11:43 PM · inputmouselook

turn mouse look on and off using the 'm' key

I have a crate that opens when you press 'e' and a loot window appears thats when i want to disable my FpsMouseLook then when im done picking my item and close the loot window i can turn the FpsMouseLook back on using the same button to turn it off 'm' I can turn it off but cant get the mouselook to turn back on. here what i got please help

 public enum RotationAxis {MouseX = 0, MouseY = 1}

      var RotationAxisRotationXY = RotationAxis.MouseX || RotationAxis.MouseY;
      
      
      
      var sensitivityX : float = 400f;
      
      var minimumX : float = -360f;
      
      var maximumX : float = 360f;
      
      var RotationX : float = 0f;
      
      var OriginalRotation : Quaternion;
      
      



     var RotationY : float = 0f;
     
     var minimumY : float = -25f;
     
     var maximumY : float = 25f;
     
     var sensitivityY : float = 400f;
     
     



function Update () {

        //******************Here is where im trying to turn it on and off***********//
       if(Input.GetButton ("Fire1") && GetComponent (FpsMouseLook))
         Destroy (GetComponent (FpsMouseLook));
       //*************************************************************************//
         if(RotationAxisRotationXY == RotationAxis.MouseX){

     RotationX += Input.GetAxis ("Mouse X") * sensitivityX * Time.deltaTime;

         RotationX = ClampAngle (RotationX, minimumX, maximumX);
                     
         OriginalRotation = XQuaternion = Quaternion.AngleAxis (RotationX , Vector3.up);

          transform.localRotation = OriginalRotation * XQuaternion;

                     
         }
         if(RotationAxisRotationXY == RotationAxis.MouseY){
         
         RotationY -= Input.GetAxis ("Mouse Y") * sensitivityY * Time.deltaTime;

         RotationY = ClampAngle (RotationY, minimumY, maximumY);
                                 
         OriginalRotation = YQuaternion = Quaternion.AngleAxis (RotationY, Vector3.right);
         
         transform.localRotation = OriginalRotation * YQuaternion;
         
         }

     }
     
     

     
 static function ClampAngle (Angle, min, max): float {
 
             
     if(Angle < -360){
     Angle += 360;
     
     }
     if(Angle > 360){
     
     Angle -= 360;
     }
     
     return Mathf.Clamp (Angle, min,max);
     

 }
Comment
Add comment · Show 3
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 syclamoth · Oct 15, 2011 at 11:45 PM 0
Share

It probably doesn't help that you're actually destroying the mouselook component, ins$$anonymous$$d of setting

 GetComponent(Fps$$anonymous$$ouseLook).enabled = aBooleanWhichSetsWhetherItsOn;
avatar image jsquiz82 · Oct 16, 2011 at 05:38 AM 0
Share

Well I tried this and it still does the same thing it turns off but wont turn back on.

if(Input.GetButton ("Fire1") && GetComponent (Fps$$anonymous$$ouseLook)) GetComponent("Fps$$anonymous$$ouseLook").enabled = false; else GetComponent("Fps$$anonymous$$ouseLook").enabled = true;

avatar image syclamoth · Oct 16, 2011 at 05:48 AM 0
Share

Is this all happening inside said Fps$$anonymous$$ouseLook? Because that would explain why it isn't working.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Proportion · Oct 16, 2011 at 06:16 AM

lol yea if that script is fpsmouselook, if you destroy it you cant use that script to turn in on. instead just wrap what u want to turn on and off in a big if.

 if(getkey("m")
 haveIPressedMBoolean = true

 if(haveIPressedMBoolean)){

 //all your fps script
 
 }


Comment
Add comment · Show 2 · 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 jsquiz82 · Oct 16, 2011 at 07:18 AM 0
Share

thanks guys thats exactly what i was doing?

avatar image asafsitner · Oct 16, 2011 at 09:47 AM 0
Share

What syclamoth was saying is, if you disable the script that checks for the input then it won't check for the input that turns it back on.

One way to solve this is to have an external script check for user input and set the bool from outside.

Another way is to break your mouse look Update into two different functions, one for the FPS mouse look and one for the other and use an if check in Update to deter$$anonymous$$e which one to call. i.e:

 function Update()
 {
     FPSbool = Input.Get$$anonymous$$eyDown("m");
     if (FPSbool)
         FPS$$anonymous$$ouseLook();
     else
         Other$$anonymous$$ouseLook();
 }
avatar image
0

Answer by bayoudarwin · Oct 16, 2011 at 11:12 AM

thanks for his input article

Comment
Add comment · 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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

Pause Menu Wont Disable Mouse,Pause menu wont disable Player Controls 0 Answers

How to keep my cursor inside window boundaries 0 Answers

Baffling Input.Mouseposition problem. If statement not correctly working. 1 Answer


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