Namaste Developers. _/\
My game has a theme of ‘Survival Shooter’.
Every Enemy has 2 different colliders
(Capsule Collider & Sphere Collider).
Now, when I use Physics.OverlapSphere for the explosion or making a Tornado Effect, the enemy got killed but it is counting the Enemy DeathCount twice (1 Enemy Killed = 2 Enemy Death Count & Score Value = 20). It is so because I have 2 different colliders on enemy gameObject. When I turn off Sphere Collider then it is counting the death count and Scores normally i.e., 1 enemy killed = 1 enemy deathcount and Score value = 10. My Sphere Collider is a Triggered Collider and my Tornado also has a Sphere collider which is a Triggered too. My Tornado has a script. Below is my code.
private void OnTriggerStay(Collider other)
{
colliders = Physics.OverlapSphere(transform.position, Radius, CollidingLayerMask, QueryTriggerInteraction.Ignore);
foreach (Collider Hit in colliders)
{
Rigidbody RB = Hit.GetComponent<Rigidbody>();
if (RB != null)
{
RB.AddExplosionForce(Power, transform.position, Radius, 5.0f, ForceMode.Acceleration);
}
if ((RB != null) && (Hit.gameObject.tag == "Enemies" || Hit.gameObject.tag == "Birds"
|| Hit.gameObject.tag == "DYZ" || Hit.gameObject.tag == "Ghost" || Hit.gameObject.tag == "RBOSS"
|| Hit.gameObject.tag == "YBOSS" || Hit.gameObject.tag == "SBOSS"))
{
Hit.GetComponent<NavMeshAgent>().enabled = false;
RB.constraints &= ~RigidbodyConstraints.FreezePositionY;
Instantiate(TornadoDeathFx, onePosition.position, onePosition.rotation);
Instantiate(CoinPrefab, onePosition.position, CoinPrefab.transform.rotation);
RB.AddExplosionForce(Power, transform.position, Radius, 5.0f, ForceMode.Impulse);
EH = Hit.GetComponent<EnemyHealth>();
EH.TakeDamageFromTornado(100);
}
}
}
It’s been so long I am suffering from this problem. I am frustrated and I am loosing my edge.
The edge which strikes fuel for the ‘Game Development’.
Any Help will be heartily appreciated.