Need help with collision

Hey guys I am new to unity and need some help.

Im trying to do collision for when the enemy collides with the player the player object will destroy but I cant seem to get it working. I have tagged the enemy with the tag “enemy”

here is the code I have for player

using UnityEngine;
using System.Collections;
public class player : MonoBehaviour {
    public float speed = 5.0f;
    void OnTriggerEnter(Collider other)
       if(other.gameObject.tag == "enemy")
    // Use this for initialization
    void Start () {
    transform.position = new Vector3(0,-10,10); // sets the posistion of the object
    // Update is called once per frame
    void Update () {
    transform.Translate(Vector3.right * Input.GetAxis("Horizontal") * speed * Time.deltaTime);
    transform.Translate(Vector3.up * Input.GetAxis("Vertical") * speed * Time.deltaTime);

any help and tips you guys have will be very helpful :slight_smile:

Is the ‘Is Trigger’ flag set on your player collider? If not, you might want to use OnCollisionEnter instead of OnTriggerEnter. Also, be sure that you have a rigidbody attached to at least one of the objects.

The whole idea seems wrong: a trigger only detects rigidbodies or CharacterControllers that enter it, and even these must be moved with the appropriate functions (with forces, for rigidbodies, and Move or SimpleMove for CharacterControllers). Alternatively, a moving trigger may have a kinematic rigidbody - this allows the trigger to detect when it touches a rigidbody or CharacterController.

You could add a CharacterController to your player, and move it with the appropriate code (see 1 and SimpleMove examples). If the enemies move, they should have rigidbodies (use OnCollisionEnter) or CharacterControllers as well. CharacterControllers have a weird characteristic: they don’t generate any event when colliding with other CharacterControllers, thus we must add a trigger to them and use OnTriggerEnter events - take a look at this answer.