Game Development Reference
In-Depth Information
This function is called when the melee item collides with an environmental object the
player can interact with. We send the object we want to interact with the message to
activate. From here, the other GameObject handles the rest of the interaction.
Detecting triggers
In order to call the functions that we just created, we have to create the interaction
between the melee item and the other GameObject. Add this final function to the
script:
void OnTriggerEnter(Collider col)
{
switch(col.gameObject.tag)
{
case "Enemy":
if(meleeType != MeleeType.Potion)
{
if(meleeAction == MeleeAction.ChangeHP)
ChangeHealth(col.gameObject);
if(meleeAction == MeleeAction.BuffDebuff)
BuffDebuffStat(col.gameObject);
if(meleeAction == MeleeAction.ActivateEnv)
ActivateEnvironment(col.gameObject);
}
break;
case "Environment":
if(meleeType == MeleeType.Potion)
{
if(meleeAction == MeleeAction.ChangeHP)
ChangeHealth(col.gameObject);
if(meleeAction == MeleeAction.BuffDebuff)
BuffDebuffStat(col.gameObject);
}
break;
}
Search WWH ::




Custom Search