Hello, I am making a 2d platformer game. This is my first time making a game, thus my coding skills are not my strong point. Mode of the code I am using comes from tutorials.
Basically, I want my enemy to play an attack animation, when the player enters a collider2d. I have attached this script to a box collider 2D, and whenever my player enters it, my player gets knocked back (which is good), and it also deals damage like I want it to, even the sound effect plays, but the enemy does not do the animation set for it.
This is my script so far:
using UnityEngine;
using System.Collections;
public class EnemyAttack : MonoBehaviour {
public int damageToGive;
void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "Player") {
HealthManager.HurtPlayer (damageToGive);
other.audio.Play ();
other.animation.Play ();
var player = other.GetComponent<PlayerController> ();
player.knockbackCount = player.knockbackLength;
if (other.transform.position.x <= transform.position.x)
player.knockFromRight = true;
else
player.knockFromRight = false;
}
}
}