One variable for multiple script types?

Hello!

In my game I’m setting up an enemy script, and I would like that script to have a variable for the weapon the enemy is holding, but different weapons will use different scripts. Is there a generic script variable type or something that I can use to declare the variable but have it be initialised to its specific script on Start()?

Thanks.

You can use a variable that can search in database the ID of the Weapon relative to the enemy.

Static variable is a variable who is the same on all script.
But in your case, put a variable in your enemy script and each time you will change weapon set the variable ?

There is a FPS tutorial where you can find this :

function Start () {
	// Select the first weapon
	SelectWeapon(0);
}

function Update () {
	// Did the user press fire?
	if (Input.GetButton ("Fire1"))
		BroadcastMessage("Fire");
	
	//Select weapon
	if (Input.GetKeyDown("1")) {
		SelectWeapon(0);
	}	
	else if (Input.GetKeyDown("2")) {
		SelectWeapon(1);
	}	
}

function SelectWeapon (index : int) {
	for (var i=0;i<transform.childCount;i++)	{
		// Activate the selected weapon
		if (i == index)
			transform.GetChild(i).gameObject.SetActiveRecursively(true);
		// Deactivate all other weapons
		else
			transform.GetChild(i).gameObject.SetActiveRecursively(false);
	}
}