help with laser

Can any one help me with my laser.
I have my character firing a laser (prefab) at an enemy but it wont destroy the enemy gameObject. But it will destroy it when i have the laser prefabs box colliders “is trigger” unchecked but then the laser wont move across the the screen.

This is my code for my enemies class:

using UnityEngine;
using System.Collections;

public class Enemy : MonoBehaviour 
{
    void OnCollisionEnter(Collision collider)
    {
        if (collider.gameObject.tag == "laser")
        {
            Destroy(gameObject);
        }
    }
}

Can anyone help?

You can proccess OnTriggerEnter instead of OnCollisionEnter and left “is trigger” checked :wink:

Ive tried that but i keep getting this error:

“Script error: OnTriggerEnter
This message parameter has to be of type: Collider”

1286703--58572--$error2.PNG

Fixed it!!! XD

I had “void OnTriggerEnter(Collision collider)” instead of “void OnTriggerEnter(Collider collider)”

edit.
Yeh.
:slight_smile: