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 Uriel_96 · Apr 20, 2011 at 07:50 PM · javascriptgetcomponentenable

disable/enable Mouse Look(c#) with a script of js

I am trying to disable and enable MouseLook script, and I actually know how:

GetComponent(MouseLook).enabled = false;
//or
gameObject.GetComponent(MouseLook).enabled = false;

but, the problem is that in my script I am using JavaScript and the script MouseLook is c#. And I am not doing something wrong because I already check with another script that is JavaScript and it works, so how I can make it work with JavaScript and C#?

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

7 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by StephanK · Apr 20, 2011 at 07:51 PM

So what exactly is your problem? Probably it doesn't know the Type of the c# script? Then try adding the C# script to the Plugins folder.

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 Uriel_96 · Apr 20, 2011 at 07:59 PM 0
Share

sorry, what exactly do you mean?

avatar image Bunny83 · Apr 20, 2011 at 08:55 PM 0
Share

Well, that's a problem with the build order in which scripts are compiled. Some special folders have different position within the compiling process. Sometimes it helps to place the scripts in the plugin folder to circumvent such errors. C# and JS scripts end up in seperate assemblies(DLLs). That's the reason why you can use a JS class in C# but the assembly have to be there before it can be used. It's a crosslinking problem. I would always try to use only one language ;).

avatar image
1

Answer by Uriel_96 · Apr 20, 2011 at 09:07 PM

Oh, yeah, after checking and checking questions and answers I finally found the correct answer to my question that is here: http://answers.unity3d.com/questions/39269/disabling-a-script-mouselook I only need to do this:

GetComponent("MouseLook").enabled = !GetComponent("MouseLook").enabled;

and it works :), but thanks anyway for the other answer

Comment
Add comment · Show 1 · 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 Bunny83 · Apr 20, 2011 at 11:00 PM 0
Share

Sure, that's the slow, dynamic, during runtime way... ;)

avatar image
0
Wiki

Answer by Skalde · May 29, 2013 at 12:58 PM

its actually even more basic, it looks something like this:

 var Player : GameObject;
 var MainCamera : GameObject;
 
 function Update () {
 
 Player.GetComponent(MouseLook).enabled = false;
 MainCamera.GetComponent(MouseLook).enabled = false;
 
 }

No Problem ^^

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 rush52490 · Mar 26, 2014 at 05:26 PM

 var Player : GameObject;
 var MainCamera : GameObject;
  
 function Update () {
  
 Player.GetComponent(MouseLook).enabled = false;
 MainCamera.GetComponent(MouseLook).enabled = false;
  
 }

This code works like a charm! it save me :)

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 FuzzyQuills · Aug 27, 2014 at 04:26 AM

It doesn't work for me, it keeps saying: " 'enabled' is not a member of 'component' "

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
  • 1
  • 2
  • ›

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

How to use "GetComponent" and "transform" code in dll file? 0 Answers

How to enable/disable Javascript using a C# script? 1 Answer

enable and disable boxcollider (whats wrong with my 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