AI符合攻击条件时,要来判断是否有攻击技能可以释放,如果有攻击技能,进行释放攻击,如果没有不再追击,防止被他人攻击。
用到协程计时,非常好用,推荐。
public override TaskStatus OnUpdate()
{
if (Skill_ID.Value != 0&& attacktarget.Value != null)
{
GetComponent<AI_Player>().DamageAllEnemy(Skill_ID.Value, attacktarget.Value.transform.position);
foreach (KeyValuePair<AI_Player.skill_struct, bool> skill_obj in GetComponent<AI_Player>().skilldic)
{
if (skill_obj.Key.skillid == Skill_ID.Value)
{
StartCoroutine(SetSkillBoolean(skill_obj.Key, skill_obj.Key.cd));//将释放的技能改为false,cd时间不能释放
break;
}
}
GetComponent<AI_Player>().skillsuclist.Clear();
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
private IEnumerator SetSkillBoolean(AI_Player.skill_struct skillbool,int cdtime)
{
// skillbool = false;
GetComponent<AI_Player>().skilldic[skillbool] = false;
yield return new WaitForSeconds(cdtime);
GetComponent<AI_Player>().skilldic[skillbool] = true;
}
效果如下:有一些小惊喜,突然发现像我手速慢的好像打不过AI