75 lines
1.8 KiB
C#
75 lines
1.8 KiB
C#
using NodeCanvas.Framework;
|
|
using RootMotion.FinalIK;
|
|
using UnityEngine;
|
|
using Zero;
|
|
|
|
public class NpcCombatSoldier : NpcCombatAbstract
|
|
{
|
|
[SerializeField] private Animator animator;
|
|
private static readonly int shoot = Animator.StringToHash("Attack");
|
|
|
|
[SerializeField] private float cooldownTimeShoot = 2f;
|
|
private float nextTime;
|
|
|
|
[SerializeField] private ExtGunBase gun;
|
|
[SerializeField] private AimIK aim;
|
|
|
|
private Transform oldTransform;
|
|
private PlayerTargetPosition playerTargetPosition;
|
|
|
|
public void UnAttachWeapon()
|
|
{
|
|
gun.gameObject.transform.parent = null;
|
|
gun.gameObject.AddComponent<Rigidbody>();
|
|
}
|
|
|
|
public override Status Attack(GameObject target, bool isRange)
|
|
{
|
|
nextTime += Time.deltaTime;
|
|
|
|
if (oldTransform == null || oldTransform != target.transform)
|
|
{
|
|
oldTransform = target.transform;
|
|
playerTargetPosition = target.GetComponent<PlayerTargetPosition>();
|
|
if (playerTargetPosition != null)
|
|
{
|
|
aim.solver.target = playerTargetPosition.GetTarget();
|
|
}
|
|
else
|
|
{
|
|
aim.solver.target = target.transform;
|
|
}
|
|
}
|
|
|
|
if (nextTime >= cooldownTimeShoot)
|
|
{
|
|
nextTime = 0;
|
|
animator.SetTrigger(shoot);
|
|
RangeAttack(target);
|
|
}
|
|
|
|
return Status.Success;
|
|
}
|
|
|
|
public override Status ResetCooldown()
|
|
{
|
|
nextTime = cooldownTimeShoot;
|
|
return Status.Success;
|
|
}
|
|
|
|
public override Status GetAttackStatus()
|
|
{
|
|
return Status.Success;
|
|
}
|
|
|
|
public override Status Aggressive()
|
|
{
|
|
return Status.Success;
|
|
}
|
|
|
|
private void RangeAttack(GameObject target)
|
|
{
|
|
gun.CallShoot();
|
|
}
|
|
}
|