- Home /
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.
Answer by rejwan1 · Oct 30, 2012 at 04:33 PM
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); } }
Answer by Muuskii · Oct 30, 2012 at 02:19 PM
That sounds alot like OnTriggerEnter coupled with Destroy. There's this very nice tutorial which will probably help you out alot.
Answer by helloiam · Oct 30, 2012 at 04:52 PM
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"));
} } }
Your answer
Follow this Question
Related Questions
Why is my character taking damage when attacking & why is it attacking multiple times per hit? 2 Answers
How to handle multiple colliders for one enemy and bullet. 3 Answers
Player not getting destroyed when touched by enemies 4 Answers
Detect if player is in range? 0 Answers
destroy a non-trigger object hitting a trigger object? 1 Answer