Hullo Unityers,
I’m attempting to make an ability system for my game. Basically, I have one script with a bunch of generic functions (checking if the ability is active, is it on cooldown, how many uses it has left…ect) that in turn controls a specific ability function.
Everytime the player gets a new ability, I add the specific ability script to the player. Here’s an example of an ability script…
var uses = 3;
var duration = 2.0;
var cooldown = 1.0;
var newColor = Color(0.3,0,0.3,1);
var icon : Texture;
function Activate()
{
gameObject.GetComponent(PlayerTakeDamage).MakeInvincible();
}
function Deactivate()
{
gameObject.GetComponent(PlayerTakeDamage).EndInvincible();
}
The open variables at the top are the values the “generic ability” script takes…right here…
function NewPower(newPower)
{
currentPower = newPower;
cooldown = currentPower.cooldown;
uses = currentPower.uses;
duration = currentPower.duration;
icon = currentPower.icon;
Debug.Log(icon);
var newColor = currentPower.newColor;
GetComponent(PlayerTakeDamage).ChangeColor(newColor);
GUI.GetComponent(GUIScripts).Golem(true, icon);
hasPower = true;
}
This function adds a new power to the player. The newPower argument is the new specific ability script.
As you can see, I take all the open variables and assign them to private vars in this script. This works just fine…except that I want every “specific ability” script to have an icon texture (in the icon variable).
You can see I have the open variable icon as a Texture. Since the script is being assigned to the player at runtime, I set the Default Reference of the icon variable to a texture in the Inspector. So I gathered that when the script is added to the player, the icon variable SHOULD be automatically set to this texture…right? However, it’s giving me a null value instead of my texture! I don’t understand why this is happening…all the other default values work just fine, so I’m assuming it has something to do with setting the Texture as the Default Reference in the inspector.
Whew. That was kind of long winded. Anyways, hope I explained it properly…thanks for any help!