This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
I tried attaching this directly via Add Behavior onto the animation event, but it didn't work. Then I tried to attach it via an Animation Event and that didn't work either.
public class SwordAttack : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
GameObject.Destroy(other);
}
}
It's supposed to just destroy the enemy on hit. I wanted to add more specific logic like death animations and knockback but that can wait until I understand how to do it.
Do I need to code it into when the actual attack is called in my main player script? I thought I could do I the way I tried above. Or is my code off?
I tried Googling a lot, but most of the tutorials start with adding a BoxCollider to represent the weapon and they use the OnCollision method instead. I was originally going to do that but I thought I could shortcut it (as in, the attack would only be active when I swung the sword, so I don't need to go to create a hitbox)
I also wanted to be able to write the method so that I could use it for both enemies and players, just that enemies would have 1 health (they just die) but the player would take damage.
So something simple for players like :
public void TakeDamage (int damage)
{
currentLives--;
// Check if lives are zero
if (currentLives <= 0)
{
GameOver();
}
}
Subreddit
Post Details
- Posted
- 4 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Unity2D/com...