- Home /
Interactions between scripts when using #pragma strict or on Android
Usually when I want a script to interact with another script I do something like this:
#pragma strict
var otherScript : MonoBehaviour;
function Start()
{
otherScript = gameObject.GetComponent(Script);
otherScript.variable = 1.0;
otherScript.Momo();
}
And then Unity will freak out about 'variable' and 'Momo()' not being a member of MonoBehaviour, when this totally works and is very convenient normally (when not using #pragma strict or not building for Android). How am I supposed to do interactions between scripts otherwise? I'd use SendMessage, but it seems slow and cumbersome to use for everything.
Answer by Graham-Dunnett · Jun 15, 2013 at 06:09 PM
Your script derives from MonoBehaviour. It's not a MonoBehaviour. The class you use should be the name of the class, which, for JS is the name of the file. See the last example on this page:
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html