I am having trouble making a game object destroy itself once it has collided and input of a mouse click.
The character: Unity Asset Store - The Best Assets for Game Making
The collide: Unity Asset Store - The Best Assets for Game Making
I have made the Overlord chase the Knight.
#pragma strict
var range : int;
var target : GameObject;
var speed : float=0.05;
var controller = GetComponent.<CharacterController>();
var animator = GetComponent(Animator);
function Start () {
}
function Update () {
range=Vector3.Distance(target.transform.position,transform.position);
if(range<10){
transform.LookAt(target.transform.position);
SmoothLookAt();
animator.SetFloat("speed", 0.5);
transform.Translate(Vector3.forward*speed*1.5*Input.GetAxis("Vertical"));
}
}
function OnCollisionEnter(info : Collision){
range=Vector3.Distance(target.transform.position,transform.position);
if (Input.GetMouseButton(0)){
if (range<4){
yield WaitForSeconds(1);
Destroy(gameObject);
}
}
}
However the collision does not work. The Overlord does not get destroyed.
I contacted the publisher for assistance for the Over lord but the publisher had little advice for the Collision detection.
An answer as soon as possible would be good.