Wednesday, February 21, 2024
HomeGame Developmentunity - MissingReferenceException: The item of kind 'CapsuleCollider' has been destroyed however...

unity – MissingReferenceException: The item of kind ‘CapsuleCollider’ has been destroyed however you’re nonetheless making an attempt to entry it


i exploit this code , however when the well being is under to 0 and destroy the gameobject , unity present the error “MissingReferenceException: The item of kind ‘CapsuleCollider’ has been destroyed however you’re nonetheless making an attempt to entry it.”

void OnTriggerEnter(Collider different)
    {
        if (canAttack && different.CompareTag("Participant"))
        {
            canAttack = false;
            if(different != null)
            {
                StartCoroutine(AttackPlayer(different));
            }
        }
    }
    IEnumerator AttackPlayer(Collider playerCollider)
    {
        whereas (true)
        {
            playerCollider.GetComponent<Participant>().TakeDamage(damageAmount);
            yield return new WaitForSeconds(0.1f);
        }
    }

and that i alreally verify the colider is null earlier than.

right here is the participant script

public void TakeDamage(float harm)
    {
        Well being -= harm;
        if (Well being < 0)
        {
            Die();
        }
    }

    non-public void Die()
    {
        Destroy(gameObject);
    }

i attempt to verify is null nonetheless no work, no debug log

IEnumerator AttackPlayer(Collider playerCollider)
    {
        
        whereas (true)
        {
            if (playerCollider.gameObject == null)
            {
                Debug.Log("111");
                yield break; 
            }
            playerCollider.GetComponent<Participant>().TakeDamage(damageAmount);
                yield return new WaitForSeconds(AttackSpeed);
        }
    }
```

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments

Arnavsijapati on Planet of Lana – Beta Demo
Jai Kishor Upadhyay on Planet of Lana – Beta Demo