- Home /
Collider other doesnt recognize other gameobjects
So im helping my friends with a very simple enemy. It basically just move from one end to the other and the idea is that when you touch it you die. But for some reason it doesn't see the player.`using UnityEngine; using System.Collections;
public class EnemyScript : MonoBehaviour {
public float speed = 3.0f;
void Update () {
transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
}
void OnTriggerEnter(Collider other){
if(other.collider.tag == "Player"){
Debug.Log("asdf");
Destroy(other.collider.gameObject);
}
}
} even if i dont check for a tag and just check for.. something it wont see other gameobjects and I dont get it:
using UnityEngine; using System.Collections;
public class EnemyScript : MonoBehaviour {
public float speed = 3.0f;
void Update () {
transform.position += new Vector3(speed * Time.deltaTime, 0.0f, 0.0f);
}
void OnTriggerEnter(){
Debug.Log("asdf");
}
} `
Im not sure what causes this so im just gonna list all the components on the enemy and player.
Enemy(untagged): the script, Box Collider 2D(which is checked as trigger) Player(tagged with "Player"): A movement script that doesn't interfere with triggers or anything of the sort, 2D Box Collider, Rigidbody2D. Both are on the default layer.
Try Destroy(other.gameobject)
Also, does the Debug.Log appear?
Answer by SkaredCreations · May 13, 2014 at 09:33 PM
OnTriggerEnter is for 3D colliding objects, since you want 2D collisions then you need OnTriggerEnter2D