Game Development Reference
In-Depth Information
void Activate()
{
switch(selfAction)
{
case SelfAction.BuffDebuff:
BuffDebuffStat();
break;
case SelfAction.ChangeHP:
ChangeHealth();
break;
case SelfAction.ChangeArmor:
ChangeArmorAmount();
break;
}
if(selfType == SelfType.Potion)
Destroy(gameObject);
}
When this function is called, we use a
switch
statement to check the
selfAction
variable. This is an easy way to see what the item should do when the player uses
it. At the end of the
Activate
function, we check to see what type of item it is. If it
is a potion, we destroy the GameObject. Not all items get destroyed upon use, such
as armor, so we use the
selfType
variable to determine what type of item it is.