x


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#?

more ▼

asked Apr 20 '11 at 07:50 PM

Uriel_96 gravatar image

Uriel_96
945 61 70 81

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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

more ▼

answered Apr 20 '11 at 09:07 PM

Uriel_96 gravatar image

Uriel_96
945 61 70 81

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

Apr 20 '11 at 11:00 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

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 ^^

more ▼

answered May 29 at 12:58 PM

Skalde gravatar image

Skalde
44 1 2

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 20 '11 at 07:51 PM

StephanK gravatar image

StephanK
6k 40 53 93

sorry, what exactly do you mean?

Apr 20 '11 at 07:59 PM Uriel_96

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 ;).

Apr 20 '11 at 08:55 PM Bunny83
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5272
x3570
x422
x143

asked: Apr 20 '11 at 07:50 PM

Seen: 3350 times

Last Updated: May 29 at 12:59 PM