I am new to Unity (Currently learning Javascript) and I am currently trying to use the “Is Trigger” option on a sphere tagged “Enemy” to collide with a cube tagged “Player”. The cube can move on the x and z planes and the sphere follows the cube’s path. Once the two collide then the sphere should be destroyed.
My problem is that when the sphere collides with the cube, nothing happens. It will only be destroyed if I move the cube.
This is the script that I have for the sphere:
#pragma strict
var player : Transform;
var moveSpeed = 5;
var maxDist = 10;
function Start () {
}
function Update () {
transform.LookAt(player);
if(Vector3.Distance(transform.position,player.position) <= maxDist) {
transform.position += transform.forward * moveSpeed * Time.deltaTime;
}
}
function OnTriggerEnter (other : Collider) {
if (other.tag == "Player") {
Destroy(gameObject);
}
}