40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Koptilnya.StateMachine;
|
|
using Mirror;
|
|
using UnityEngine;
|
|
|
|
namespace Characters.Enemy.States
|
|
{
|
|
public class AttackState : State<EnemyState>
|
|
{
|
|
private readonly Enemy _enemy;
|
|
private static readonly int AttackAnimHash = Animator.StringToHash("attack");
|
|
private readonly AudioClip _attackClip;
|
|
|
|
public AttackState(Enemy enemy) : base(EnemyState.Attack)
|
|
{
|
|
_enemy = enemy;
|
|
_attackClip = Resources.Load<AudioClip>("Audio/EnemySounds/FX/attack");
|
|
}
|
|
|
|
public override void Enter()
|
|
{
|
|
if (_enemy.isServer)
|
|
{
|
|
_enemy.networkAnimator.SetTrigger(AttackAnimHash);
|
|
_enemy.RpcKillTarget(_enemy.targetTransform);
|
|
_enemy.ChangeState(EnemyState.Idle);
|
|
}
|
|
|
|
if (_enemy.isClient)
|
|
{
|
|
_enemy.audioSource.PlayOneShot(_attackClip);
|
|
}
|
|
}
|
|
|
|
[ServerCallback]
|
|
public override void Exit()
|
|
{
|
|
_enemy.targetTransform = null;
|
|
}
|
|
}
|
|
} |