Answer the question
In order to leave comments, you need to log in
Why is the object not destroyed when touched?
Box Collider set up, object specified
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public GameObject Car;
void Start () {
}
void Update () {
if (Vector3.Distance(Car.transform.position,transform.position) < 1f)
{
Destroy(Car);
}
}
}
Answer the question
In order to leave comments, you need to log in
Well, colliders have nothing to do with it at all - you don't use them in your code.
And not destroyed perhaps because the distance never becomes <1. The distance is measured from the center of the object - and if each object you have is 1 - then the distance will be <1 when they are half inside each other.
The way out is to use colliders.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question