Distance destroy object

My question as follow:

I heard from trigger on enter that can be used as example: when I go in a object or something else that the object destroy himself.
Thank you all.

Kind regards,

helloiam.

I’m assuming what you meant is once a game object enters a trigger collider, you want to destroy that game object.

So if that’s true, you need the following:

  • A trigger collider

  • A game object with a collider and a rigidbody

  • On the game object script, add the following code

    void OnTriggerEnter(Collision collision)
    {
    if (collision.collider.gameObject.tag == “Tag you are looking for”)
    {
    Destroy(gameObject);
    }
    }

That sounds alot like OnTriggerEnter coupled with Destroy. There’s this very nice tutorial which will probably help you out alot.

Hi,

Thank you for reacting on my post, but the problem is that this is .javascript and I script
in C#, my question is simple.
What I thought is

private void OnTriggerEnter(Collider Enemy)
{
Destroy(GameObject.FindGameObjectsWithTag(“Enemy”))
}

Or with a distance, that’s when you come about a distance the object destroy.

private ByaDistanceDestroyObject()
{
float distance = Vector3.Distance(target.transform.position, transform.position);
Vector3 dir = (target.transform.position - transform.position).normalized;
float direction = Vector3.Dot(dir, transform.forward);
Debug.Log(direction);
if(distance < 18.5f){
if(direction > 0){

Destroy(GameObject.FindGameObjectsWithTag(“Enemy”));

}
}
}