OnTriggerEnter2D Not Working
Rigidbody2D is not set to kinematic, OnTriggerEnter2D is spelled correctly and my box collider 2D is a trigger, and its not working...
using UnityEngine;
using System.Collections;
public class Damage : MonoBehaviour {
public float Damage2 = 50;
public AudioSource SoundEffect;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
other.GetComponent<HealthSystem>().Damage = Damage2;
SoundEffect.Play ();
}
}
}
I meant the collision partner. you described only one member, right? if not, the other object might not have a collider.
I have a character with an axe as a weapon, the axe itself has the script attached to it, and activates it when needed. It also has a 2d box collider trigger.
and you're trying to hit enemies which have colliders? How is everyone moving? translating? If so switch to addforce or velocity. animation should run in physics update mode... your info is just not enough to guess more.
Every character in my scene is using a 2D box collider, they move by adding velocity to their rigidbodies. Im using $$anonymous$$ecanim to animate each character. $$anonymous$$y melee weapon system works by enabling a gameobject with a collider on it with the Damage script. When you press the spacebar, the character will do an animation where he swings his axe. The collider is enabled during this animation. However, if you try to use your axe on an NPC, nothing happens. No errors, nothing.
http://oi61.tinypic.com/2wrnqso.jpg
In the image above, you can see that the axes damage trigger is clearly co$$anonymous$$g in contact with the character, yet nothing happens.
Answer by hexagonius · Sep 19, 2015 at 11:13 PM
the animation looks quite fast. Is the position fix relative to the player? because then an overlapcircle might do.
Oh, ok. I slowed the animation and its working now. Thanks for your help.
Edit: Never$$anonymous$$d, its still not triggering. But the wierd thing is that if I add the damage script to a gameobject with nothing other then a box collider trigger, then it works.