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 Pe-ads · Sep 16, 2011 at 04:04 PM · cameradisablemouselook

MouseLook not being disabled when attached to a camera

I'm writing a script to disable moving the camera and moving the character when certain variables are true/false. It works fine, except for the script attached to the camera (I have the same problem in a similar script that handles pausing).

Here's my code:

 var inUse : boolean = false;
 var charControllerDisabled : boolean = false;


 private var FirstPersonController : GameObject;

 function Start() {

 FirstPersonController = GameObject.Find("FirstPersonController");

 }

 function Update () {
 
 if(inUse && !charControllerDisabled){
     
         
     FirstPersonController.GetComponent("CharacterController").enabled = false;
     FirstPersonController.GetComponent("MouseLook").enabled = false;    
     FirstPersonController.GetComponent("CharacterMotor").enabled = false;
     FirstPersonController.GetComponent("FPSInputController").enabled = false;
     
     FirstPersonController.GetComponentInChildren(MouseLook).enabled = false;
     
         
 
 
 
     }

 }

I suspect the problem is that the camera is not a GameObject but a Camera. However, I've tried referencing the Camera directly, and that didn't work either. Any help would be appreciated.

Comment
Add comment · Show 2
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 BerggreenDK · Sep 16, 2011 at 07:34 PM 1
Share

Just a comment: pulling "GetComponet" each frame (through Update that runs 60 fps) is RATHER BAD for performance. You should move those calls into a seperate function and ONLY call it when something changes.

IF you need to access them each frame, then consider to store the result (the Component pointer object) in a class-local variable and then use .enable on that object.

avatar image Pe-ads · Sep 17, 2011 at 01:44 PM 1
Share

Thanks a lot! I'll make sure to change that in my code. Always forget that I should initialize stuff in the variables :-P

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Clunk · Sep 16, 2011 at 05:16 PM

Here is what I tried, worked for me :)

 Camera.mainCamera.GetComponent("MouseLook").enabled = false;

Clunk47@Gmail.com

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 Pe-ads · Sep 17, 2011 at 01:42 PM 0
Share

I'll try that tonight, thanks!

avatar image Pe-ads · Sep 18, 2011 at 04:10 PM 0
Share

Works perfectly, thanks! I haven't had much experience with the Camera object, so this syntax is fairly new to me: thanks for helping me out :D

avatar image Clunk · Sep 18, 2011 at 07:35 PM 1
Share

No problem, very happy I could help! :)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Script to disable MouseLook? 2 Answers

Turn Off/on culling mask by script? 2 Answers

Stop Motion Camera Effect 0 Answers

How to set y-axis limits to mouselook script 1 Answer

Want Object to move freely in Camera's Limit 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