How would I set an instance of an object?

I’m basically trying to check a variable from one Game Objects script and set it equal to a different variable in another Game Objects script, but I’m not sure of the best way to go about it. weapon1 is a variable (game object) on the WeaponHandler script, I need currentWeapon to contain the same game object as weapon1 when the script begins.

If anyone can see where I’m going wrong here I’d be grateful :slight_smile:

Thanks

var currentWeapon : GameObject;
var weaponHandlerInstance : WeaponHandler;

function Start ()
{
    currentWeapon = weaponHandlerInstance.weapon1;
}

Either weapon1 needs to be public or you should create a getter. However, your problem probably is, that you cannot really count on script execution order. You can set some order in settings though. Question here is: is your script design good? Do you really need this setup?