- Home /
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 :)
Thanks
var currentWeapon : GameObject;
var weaponHandlerInstance : WeaponHandler;
function Start ()
{
currentWeapon = weaponHandlerInstance.weapon1;
}
Answer by Lovrenc · Jan 26, 2013 at 06:39 PM
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?
Thanks for the reply. Yea I already tried making it as public and it didn't work. I've never attempted a getter, what would be the best way of doing that?