I am currently working on a project where I want the player to punch high objects and kick low objects. I am new to coding but I do have some experience. The code I have currently works but the player does not have to kick or punch for the enemy to disappear. This is what I currently have
you’ll need some more conditions.
First, well i guess it’s a 3D game, if you have a skined mesh for your player you maybe have a skeleton on your mesh ? If you have one, put a little trigger on the hand that punch and on the foot that kicks (a little trigger is only an empty child with a collider).
Now in your code, you have to set 2 booleans “isPunching” and “isKicking” that you set to true only during the punching/kicking animation.
The script should be on the player itself, but the trigger detection will be on the trigger on the hand
So on the hand, put a script like this
public GameObject player; //drop your player gameobject in the inspector
void OnTriggerEnter2D(Collider2D target)
{
if (target.tag == "Enemy"){
player.GetComonent</*Your player script*/>().enemyInTrigger = true;
player.GetComonent</*Your player script*/>().target = target.gameObject;
}
}
void OnTriggerExit2D(Collider2D target)
{
if (target.tag == "Enemy"){
player.GetComonent</*Your player script*/>().enemyInTrigger = false;
player.GetComonent</*Your player script*/>().target = null;
}
}
and on the player script something like
public bool enemyInTrigger = false;
public GameObject target;
if(enemyInTrigger && isPunching){
target.SetActive(false);
}
Will I still have to use the same concept as what you posted before for a 2D game?
The code may not be the best way to do it but that’s the only way I knew how to get the animations working.