简体   繁体   中英

the code seems to skip this code for my collider, how do I make it work?

I have visited many forums for this problem and I have searched lots of tutorials for this issue. Here's my code:

private void OnTriggerEnter(Collider collision)
{
    GameObject collisionGameObject = collision.gameObject;

    if (collisionGameObject.name == "playerBullet")
    {
        Debug.Log("damage taken");
        TakeDamage(40);
    }
}

I should be doing everything right, what went wrong?

Make sure of the following things:

  1. Your GameObject with the script must have a collider.
  2. Your GameObject with the script must be set to Collider and not Trigger
  3. Your GameObject with the script must have a RigidBody
  4. Your Bullet must have a collider.
  5. Your Bullet must have a collider that is not a trigger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM