So I’m making a simple hack and slash game in C#. I have two colliders on each enemy their physical collider so the player can’t run through them and an “aggro” collider that makes the enemy interact with the player when he enters. The player also has two colliders their physical collider and their targeting collider. For targeting the enemy I have this code
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag (“Skeleton”))
{
{
enemyinrange = true ;
target = other.gameObject ;
skelehp = target.gameObject.GetComponent ();
}
}
}
void OnTriggerExit(Collider other) {
if (other.gameObject.CompareTag (“Skeleton”))
{
enemyinrange = false ;
}
}
void OnTriggerStay(Collider other)
{
if (other.CompareTag (“Skeleton”)) {
enemyinrange = true;
}
}
void FixedUpdate ()
{
if (Input.GetButtonDown (“Fire1”) && enemyinrange)
{
skelehp.skeletonhp = skelehp.skeletonhp - 5;
}
if (skelehp.skeletonhp == 0)
{
Destroy (target);
enemyinrange = false;
}
}
So my problem is whenever I enter the enemies “aggro” collider which is a lot bigger than their physical collider, I can do damage to them. Is there a way I can get it so when my targeting colldier enters the enemies physical colldier I can attack then? This is my first bigger project so I’m still unsure of some code or techniques through unity, hence why I’m asking for help.