What could this error mean?

I’m making this soldier script for the asset store, but someone is getting a specific error and I don’t know what could be causing it!

My guess this is about how I pass the variables from one script to the other.
I’m passing variables from one script to the other using GetComponent()

For example, fallSpeed is a global variable in soldier.js, and I get the variable like this

private var soldierScript : MonoBehaviour;

function Start(){
   soldierScript = soldier.GetComponent("soldier");
}

function Update{
    var fallSpeed : float = soldierScript.fallSpeed;
}

Everything works in my computer, but in his computer he’s getting this error:

SoldierCamera.js; fallspeed is not a member of unity.monobehaviour

What do you guys think might be causing that, and how do I solve it?

It’s because the type of soldierScript is set to MonoBehaviour in its declaration. Set it to Soldier (or whatever the script is called) instead.

A script is an object in Unity, meaning that if you create a script called Soldier.js then you can create variables of that object type, like so:

var myScriptVariable : Soldier;

When you then fetch the script from another component you do not need to add the quotes, because what you are getting is the entire script (in this case Soldier) object, with all its variables and whatnot. So to get the reference to the Soldier.js script on a gameobject you do as follows:

 myScript = GameObjectReference.GetComponent(Soldier);

In this example I already have a reference to the object that contains the script (GameObjectReference). Now let’s say that you have a variable named speed, then you can simply modify/access it as follows:

myScript.speed = 10;

or

if(myScript.speed > 10)

Remember that the variable speed need to be set explicitly as public if it resides in a C# script. In javascript it is the other way around, where it is public (accessible from other scripts) as long as it is not set to private.

Hope it helps, and as someone who have bought your soldier I must say it is a really fine asset. Hope you’ll add more variations to it, such as different armors and weapons. Wouldn’t mind paying more if you made it an add-on :wink:

I’m glad I know this now! Thanks!!