Accessing C# component from Javascript

Hello chaps, I have a problem trying to access a C# script component from a Java script. My code is simple…

var playerObject :GameObject;
var mouseLookScript : MouseLook;//this is the name of the script (MouseLook.Cs)

function Start()
{

playerObject=(GameObject.Find("Player"));//it finds this object no problem
mouseLookScript =playerObject.GetComponent(MouseLook);//but not this component..:(

}

But my MouseLookScript var reads as nothing in the inspector…?? ie None(MouseLook)

Any idea why?

Do you get any error messages about MouseLook being undefined? If so, put the MouseLook.cs script inside the standard assets folder. Also, are you sure the object has a MouseLook component attached?

The error I get is…

Assets/MIHT_Assets/Scripts/GlobalFunctionsScript.js(9,23): BCE0018: The name ‘MouseLook’ does not denote a valid type.

at the start of my other script I am declaring the following:

var playerObject :GameObject;
var mouseLookScript : MouseLook;

and the Mouselook script is called MouseLook.cs

you must put the C# class in a build step that happens earlier than your JS compilation step so the compilation order is correct (that means putting it into folder Standard Assets - Pro Assets - Plugins basically). You can find out more about that in the advanced topic documentation

Hmm, now I have both scripts in the same folder (/customassets . This should all get compiled last right?)) and I don’t get the error but Mouselook still contains ‘none’

So does C# get compiled before Javascript then?

Actually cancel that previous msg…

Actually now I have the Mouselook in standard assets (compiled first) and the other script in another script folder (compiled last). I get no error but Mouselook is still ‘none’.

…and cancel that one too :slight_smile: Mouselook component had managed to detach itself somehow (?)

Cheers
:sweat_smile:

then there was no such component found on the player object. check if the assigned player object is correct

This is the docs on the subject: Unity - Scripting API:

Bit late to the party, eh cawas? :stuck_out_tongue: