Collision Problems
I am having trouble making a game object destroy itself once it has collided and input of a mouse click.
The character: https://www.assetstore.unity3d.com/en/#!/content/15209 The collide: https://www.assetstore.unity3d.com/en/#!/content/48768
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.
Answer by Abhiroop-Tandon · Mar 30, 2016 at 11:19 AM
You need to check the gameObject with its tag or name. In your collisionEnter you have not defined who is entering the collider. Some check like if(info.collider.gameObject.CompareTag("Overlord"));
needs to be there to know what to do. (I hope it makes sense)
Your answer
Follow this Question
Related Questions
Colliders for tunnels 0 Answers
Team Pong Colliders not working 0 Answers
OnCollisionEnter2D not getting called 2 Answers
Changing light color between players when they collide (BOLT) 0 Answers