首先通过英雄战斗脚本锁定敌人
锁定敌人时候通过移动脚本移动
当到达攻击范围触发攻击逻辑
用敌人数值的血量减去玩家数值攻击
当敌人没有血量时候敌人销毁
敌人
玩家
攻击动画启动
攻击动画关闭
英雄战斗
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HeroCombat : MonoBehaviour
{
// 英雄战斗方式
public enum HeroAttackType {
Melee,RanGed};
public HeroAttackType heroAttackType;
// 锁定敌人 攻击范围
public GameObject targetedEnemy;
public float attackRange;
//public float rotateSpeedForAttack;
// 移动脚本 统计脚本 动画组件
private Movement moveScript;
private Stats statsScript;
private Animator anim;
// 英雄生死 攻击触发
//public bool basicAtkIdle = false;
public bool isHeroAlive;
public bool perfoemMeleeAttack = true;
// Start is called before the first frame update
void Start()
{
// 实例化移动脚本
moveScript = GetComponent<Movement>();
statsScript = GetComponent<Stats>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
// 当有敌人的时候
if(targetedEnemy != null)
{
//敌人和玩家的距离超过攻击范围
if (Vector3.Distance(gameObject.transform.position,targetedEnemy.transform.position) > attackRange)
{
// 向敌人方向前进达到攻击范围停止
moveScript.agent.SetDestination(targetedEnemy.transform.position);
moveScript.agent.stoppingDistance