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 Ian-McCleary · Jun 18, 2015 at 11:39 PM · javascriptscript errordisablemouselook

Unable to disable the MouseLook script

I have a section of code that i want to disable the mouse script when the button I is pressed. I know there is a better way to do it, such as making a variable for GUI and a funciton such as showGUI = !showGUI, but im not 100% sure on how to set that up with disabling all the moving scripts.

I am using the old MouseLook and Character controller script because i despise the new one. I also think these are easier to work with.

Errors: NullReferenceException: Object reference not set to an instance of an object Inventory.Update () (at Assets/Scripts/Inventory.js:92)

NullReferenceException: Object reference not set to an instance of an object Inventory.Update () (at Assets/Scripts/Inventory.js:82)

Section of code line 5=line 82 (It had no problem on the one directly after)

 if(showGUI == true)
     {
         Time.timeScale = 0;
         GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = false;
         GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = false;
         GameObject.Find("Main Camera").GetComponent(MouseLook).enabled = false;
         GameObject.Find("Arms05").GetComponent(PlayerControl).enabled = false;
         GameObject.Find("Main Camera").GetComponent(RayCastChop).enabled = false;
     }
     
     if(showGUI == false)
     {
         Time.timeScale = 1;
         GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = true;
         GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = true;
         GameObject.Find("Main Camera").GetComponent(MouseLook).enabled = true;
         GameObject.Find("Arms05").GetComponent(PlayerControl).enabled = true;
         GameObject.Find("Main Camera").GetComponent(RayCastChop).enabled = true;
     }
 }

Comment
Add comment · Show 4
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 maccabbe · Jun 18, 2015 at 11:55 PM 0
Share

Do you have two $$anonymous$$ouseLook components, one attached to a gameObject named "First Person Controller" and another attached to a gameObject named "$$anonymous$$ain Camera"?

avatar image Ian-McCleary · Jun 19, 2015 at 12:12 AM 0
Share

@maccabbe Yes

avatar image Nerevar · Jun 19, 2015 at 07:42 AM 0
Share

from doc :

it is better to use GetComponent with a Type ins$$anonymous$$d of a string for performance reasons. Sometimes you might not be able to get to the type however, for example when trying to access a C# script from Javascript. In that case you can simply access the component by name ins$$anonymous$$d of type.

so shouldn't it be GetComponent("$$anonymous$$ouseLook") ?

avatar image Ian-McCleary · Jun 19, 2015 at 10:47 PM 0
Share

this might work, but then i cannot disable it by putting .enabled = false unless there is another way.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Boggs · Jun 30, 2015 at 10:59 PM

The only way I got it to work was to modify the MouseLook.CS script by adding 2 ifStatements to the X & Y Sensitivity floats to "0" and 2 ifStatements to return value back to "2". Hope this helps if someone has a better way plz share.

 using System;
 using UnityEngine;
 using UnityStandardAssets.CrossPlatformInput;
 
 namespace UnityStandardAssets.Characters.FirstPerson
 {
     [Serializable]
     public class MouseLook
     {
         public float XSensitivity = 2f;
         public float YSensitivity = 2f;
         public bool clampVerticalRotation = true;
         public float MinimumX = -90F;
         public float MaximumX = 90F;
         public bool smooth;
         public float smoothTime = 5f;
 
 
         private Quaternion m_CharacterTargetRot;
         private Quaternion m_CameraTargetRot;
             
         public void Init(Transform character, Transform camera)
         {
             m_CharacterTargetRot = character.localRotation;
             m_CameraTargetRot = camera.localRotation;
         }
 
 
         public void LookRotation(Transform character, Transform camera)
         {
                          
             float yRot = CrossPlatformInputManager.GetAxis ("Mouse X") * XSensitivity;
             float xRot = CrossPlatformInputManager.GetAxis ("Mouse Y") * YSensitivity;
 
             m_CharacterTargetRot *= Quaternion.Euler (0f, yRot, 0f);
             m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);
 
             if (Input.GetMouseButtonDown (2))
                 Debug.Log (YSensitivity = 0f);
 
             if (Input.GetMouseButtonDown (2))
                 Debug.Log (XSensitivity = 0f);
                 
             if (Input.GetMouseButtonDown (1))
                 Debug.Log(YSensitivity = 2f);
 
             if (Input.GetMouseButtonDown (1))
                 Debug.Log(XSensitivity = 2f);
                 
         if (clampVerticalRotation)
             m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
 
             if(smooth)
             {
                 character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
                     smoothTime * Time.deltaTime);
                 camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
                     smoothTime * Time.deltaTime);
             }
             else
             {
                 character.localRotation = m_CharacterTargetRot;
                 camera.localRotation = m_CameraTargetRot;
             }
         }
 
 
         Quaternion ClampRotationAroundXAxis(Quaternion q)
         {
             q.x /= q.w;
             q.y /= q.w;
             q.z /= q.w;
             q.w = 1.0f;
 
             float angleX = 2.0f * Mathf.Rad2Deg * Mathf.Atan (q.x);
 
             angleX = Mathf.Clamp (angleX, MinimumX, MaximumX);
 
             q.x = Mathf.Tan (0.5f * Mathf.Deg2Rad * angleX);
 
             return q;
         }
 
     }
 }
 
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
avatar image
0

Answer by siblingrivalry · Jul 05, 2015 at 09:23 PM

Hi, are you using unity4 First Person Character controllers inside Unity5?

If so, just move the Unity4 character controller in to the "Standard Assets" folder where the Unity 5 controller lives.

Then MouseLook is working without needing to hack the Mouselook.CS

hope that helps.

-original answer by @SG|Gamer

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

24 People are following this question.

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

Related Questions

Disable all instances of a component 2 Answers

Script to disable MouseLook? 2 Answers

disabling a script (MouseLook) 5 Answers

How to Disable Mouse and Character movement? (Javascript) 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 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