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 Grefuntor · May 07, 2012 at 01:53 AM · javascriptdisablemouselookenable

Disable all instances of a component

I am trying to disable mouse look on 'q'.

Here is my code as is.

 #pragma strict
 //Variables
 public var paused = false;;
 
 //This script is on the main camera
 function Start () {
 
 }
 
 function Update () {
     
     if(Input.GetKeyDown("q")){
         paused = !paused;
         
     }
     if(paused){
         //Toggle caputred cursor
         Screen.lockCursor = false;
         //disable mouselook
         //This needs to be changed to disable the FPS controllers script
         GetComponent(MouseLook).enabled = false;
         //This should kill the cameras script
         Camera.mainCamera.GetComponent(MouseLook).enabled = false;
         Time.timeScale = 0;
     }
     if(!paused){
         Screen.lockCursor = true;
         GetComponent(MouseLook).enabled  = true;
         Camera.mainCamera.GetComponent(MouseLook).enabled = true;
         Time.timeScale = 1;
     }
 
         
 
 }
 


The issue is that it only disables it on one axis (e.g cameras axis or players axis ).

So how do i disable both scripts and re-enable both scripts on the generic First Person Controller?

-Grefuntor

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 GC1983 · May 07, 2012 at 02:03 AM 0
Share

What "both" scripts? I see you only trying to access $$anonymous$$ouseLook.

I also would recommend not referencing scripts during execution. You should only need to access them once at the start of the scene.

Create a variable such as LookFor$$anonymous$$ouse and assign it to $$anonymous$$ouseLook.

var $$anonymous$$ouseLook : LookFor$$anonymous$$ouse;

Then place LookFor$$anonymous$$ouse = GetComponent("$$anonymous$$ouseLook"); within the Awake(). The script will be available the rest of the time during game play. If you call for the component everytime you use those if statements, it will hurt your games performance.

Then within your if statements, activate or deactivate them through LookFor$$anonymous$$ouse.enabled = true or false;

What exactly; is it doing right now? Are you getting any errors?

avatar image Grefuntor · May 07, 2012 at 02:11 AM 0
Share

Right now it does work. But it only stops me from looking up and down. I need to disable mouselook, but the default set-up has 2 mouselook scripts for some reason, and i need to stop them both.

Edit: let me clarify that- $$anonymous$$ouse look is the component i want to stop, but there seems to be more than one on the player.

avatar image Eric5h5 · May 07, 2012 at 02:47 AM 0
Share

@GC83: you shouldn't use quotes in GetComponent, but it doesn't really make any difference whether you cache the call if you're just doing it occasionally. Also the convention is to use lowercase for variables (uppercase for functions and classes).

avatar image GC1983 · May 07, 2012 at 02:51 AM 0
Share

To each their own. But, I suppose it would help for clarifying variable types.

2 Replies

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

Answer by DaveA · May 07, 2012 at 02:30 AM

I'm not sure why you would want or need 2 MouseLooks on one object, but you could use GetComponents(MouseLook) to get a list of them, then use a 'for' loop to set each's enables as needed.

Comment
Add comment · Show 8 · 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 Grefuntor · May 07, 2012 at 02:31 AM 0
Share

I didn't set it like that... It's just the standard First person controller. Will try the for loop.

avatar image Lo0NuhtiK · May 07, 2012 at 02:35 AM 1
Share

The FPS has one $$anonymous$$ouseLook on the 'body' and one on the camera ('head') ... I assume it's because when looking up/down it 'tilts', so if this were on the body of the controller, it would be upsetting it's stance/balance. $$anonymous$$inda like if your neck, spine and knees were locked and you could only look up/down by pivoting on your ankles.

avatar image Grefuntor · May 07, 2012 at 02:40 AM 0
Share

$$anonymous$$akes (some) sense. How should I go about disabling this? I'm not sure of how I should be doing this. I tried GC83's suggestion, but 'var $$anonymous$$ouseLook : LookFor$$anonymous$$ouse;' threw an error.

avatar image GC1983 · May 07, 2012 at 02:42 AM 0
Share

Sorry, backwards. LookFor$$anonymous$$ouse : $$anonymous$$ouseLook;

avatar image Eric5h5 · May 07, 2012 at 02:50 AM 1
Share

@Grefuntor: do what Dave A said, although you would need GetComponentsInChildren rather than GetComponents. The docs even have a code example doing exactly what you want.

Show more comments
avatar image
0

Answer by LauraCortes · Dec 13, 2012 at 08:18 PM

http://answers.unity3d.com/questions/53917/mouse-look-and-character-motor-off-but-i-can-still.html I think haxard's answer is what you need.

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

8 People are following this question.

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

Related Questions

How to disable/enable SSAOEffect or other specific Components? 1 Answer

How to Disable/Enable another Script with Triggers? 1 Answer

How do I disable The MouseLook script when "I" is pressed. 3 Answers

Disable C# Script from Java Script 1 Answer

Unable to disable the MouseLook script 2 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