Collision being ignored

I am having trouble in making a cillinder show a message when it hits an Enemy. I was seeing a video about Counter-Strike when i thought “Oh, it would be a nice idea to use that same system!” Most FPS games use an invisible line that when find an enemy, activate a trigger that will make the enemy be hit instantly.

This makes impossible for the enemy to dodge hits, but it is very easy to make and pretty nice by the way. It would reduce my things to do list for now (i am developing the enemy) in my FPS.

The problem is that something is wrong here… I don’t know if it is bcs i have been studying literally 3 different programming languages and i am kinda forgotting the basic things sometimes, but something is wrong with my script.

I made a simple script for now that WAS SUPPOSED to detect any gameobject that collide with my cillinder. When it collides, the script will detect if it is an enemy by searching if it is tagged as “Enemy”. (Javascript)

function OnCollisionEnter (Aim : Collision)
    {
        if(Aim.gameObject.tag == "Enemy")
        {
            Debug.Log ("TARGET HIT!");
        }
    }

The problem is that basically… It doesn’t show the log! Why? I also changed it to just (Collision: Collision) and nothing changes, the log isn’t shown. My cillinder does have a collider, the enemy does have a collider, i don’t understand! Is it because i have two cameras or something? Also my cillinder is passing through objects. =(

Edit: Here are two screen shots. One is of my current test cillinder, and the other is from the Enemy. Hope it helps!

Is the Cylinder a trigger? Also, try just Debug.Log outside of the if statement so that when the enemy hits anything it will log it just for a test, if or when that works you can delete it and do further testing

You need a rigidbody component attached to your enemy.

“With normal, non-trigger collisions, there is an additional detail that at least one of the objects involved must have a non-kinematic Rigidbody” Unity - Manual: Introduction to collision

I don’t see my original answer so I’m posting a new one as a sort of edit to my original(if you can even see it) but also try using Aim.collider.tag instead of Aim.gameObject.tag. Not sure what the difference is but once I had a problem similar to yours and I believe it was fixed by changing that. It was a while ago though