The Variable has not been assigned.

Hi guys, i am trying to run this script to change weapons, but is not taking effect :confused:

var canChoose : boolean;

var ActualWeapon : String;

var SlotPrimary : Transform;

var SlotSecondary : Transform;

var SlotMelee : Transform;

function Awake(){

SelectWeapon ( "SetPrimary" );

}

function Update(){

if(Input.GetAxis("Mouse ScrollWheel") > 0){

	SelectWeapon ( "SetPrimary" );

}

if(Input.GetAxis("Mouse ScrollWheel") < 0){

	SelectWeapon ( "SetSecondary" );

}

}

function SelectWeapon( WeaponToSelect : String ){

if(WeaponToSelect == "SetPrimary"){
	
	SlotPrimary.active = true;
	SlotSecondary.active = false;
	SlotMelee.active = false;

}

if(WeaponToSelect == "SetSecondary"){

	SlotPrimary.active = false;
	SlotSecondary.active = true;
	SlotMelee.active = false;

}

}

Transform.active doesn’t actually do anything. You want ‘transform.gameObject.active’ instead.

This seems like a bit of a weird way of doing things. Why don’t you save yourself a few byte of code, and make it work like this, instead?

SelectWeapon (SlotPrimary); // Will select the primary weapon!
// Instead of using strings, just use the references you *already have*!

function SelectWeapon( WeaponToSelect : Transform ){
    SlotPrimary.gameObject.active = false;
    SlotSecondary.gameObject.active = false;
    SlotMelee.gameObject.active = false;

    WeaponToSelect.gameObject.active = true;

}