Game Development Reference
In-Depth Information
if(meleeType == MeleeType.Potion)
Destroy(gameObject);
}
To detect the contact between the melee item and GameObject that the player hits,
we use OnTriggerEnter to activate our functions. When the melee item enters a
triggered GameObject, the OnTriggerEnter function is called and it will receive
the GameObject that it entered.
From here, we use a switch statement to check the tag of the trigger GameObject.
Using a tag is a quick way to check what the player hit with their melee item. Once
we find the correctly tagged GameObject, we check the meleeType variable and
then the meleeAction variable.
Depending on the type of melee item, we decide what the item can and can't do.
In both case statements, we check whether the melee type is a potion or not; this
will decide whether to activate environmental objects or not. Also, at the end of the
function, we destroy the melee item if it is a potion; this ensures that potions are a
single-use item.
Search WWH ::




Custom Search