I have a ‘sword’ object, and a test enemy which is designed to follow the player when within a certain range. I have a ‘weaponScript’ which controls the mechanics and animations for the weapon. The sword has a collider and is set to IsTrigger. The problem is that this collider is hit and miss. It only detected a collision 30% percent of the time, and recently stopped working entirely when i added a corrutine to the collision event. If anyone has any solution to this, that would be very helpful. Thank you.
private void OnTriggerEnter(Collider other)
{
Debug.Log("Collision!!!!");
if (other.CompareTag("Enemy"))
{
Debug.Log("EffectBegan " + col.enabled);
Renderer m = other.GetComponent<Renderer>();
m.material.color = new Color(255, 50, 50);
EnemyBehavoir scrp = other.GetComponent<EnemyBehavoir>();
scrp.Health -= Damage * SwingMultiplier;
Debug.Log(scrp.Health);
coroutine = Wait(1.0f);
m.material.color = Color.red;
Debug.Log("EffectEnded");
}
}
private IEnumerator Wait(float waitTime)
{
yield return new WaitForSeconds(waitTime);
}
Hi @Dudeguy90539 what is the “coroutine” variable on line 15? Thanks.