- Home /
OnTriggerEnter does not work
so I have a collider script for my Player and the Enemy (player is the standard character controller)
function OnTriggerEnter(collision: Collider) {
if(collision.gameObject.name == "Player") {
Debug.Log("Is touched");
GetComponent.<Animation>().Play("attack");
}
}
I have 2 colliders on the enemy 1 set to is trigger and 1 without is trigger and that one is just for colliding with terrain and buildings. the problem however is that when my player collides with the enemy nothing happens unless I make the box collider for the terrain 0 on the Y scale and place it at the enemies feet. but then the player is able to walk through the enemy and that should not happen. I already tried making the box collider with the Istrigger on bigger than the one with it off but that doesn't do anything the enemy has a rigidbody attached to him. the character controller has it's standard components and nothing more than that
can someone tell me how I can get this to work thanks.
Answer by ScaniX · Jul 23, 2016 at 04:48 PM
I don't think you are supposed to have more than once collider on a game object. I am almost sure that this will produce some problems.
Why aren't you just using colliders with IsTrigger = false
and implement the OnCollisionEnter()
method for your behaviour?
Because the oncollisionenter method Does not work with the unity firstpersoncontroller prefab that is in the standard assets
And they aren't on the Same gameobject the one collider with is trigger off is a empty game object and is a child of the firstpersoncontroller
Your answer
Follow this Question
Related Questions
Strange issue with collider 1 Answer
2D Platformer - Picking Up Items & Storing Them C# 0 Answers
How to use different and distinguish between different box colliders? 1 Answer
Trigger Spawning? 1 Answer
OnTriggerEnter and GUIText problem 0 Answers