为什么怪物被主角打中时行为树不会打断后面的操作
ishit判断
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;
public class IsHit : Conditional {
public bool isHit;
public override void OnStart()
{
GetComponent<BehaviorTree>().FindTask<BeingAttack>().MyState = GetComponent<CharacterState>();
}
public override TaskStatus OnUpdate()
{
if (isHit)
return TaskStatus.Success;
else
return TaskStatus.Failure;
}
public void TakeDamage(int Damage)
{
GetComponent<BehaviorTree>().FindTask<BeingAttack>().Damage= Damage;
}
}
BeingAttack
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;
public class BeingAttack : Action {
public CharacterState MyState;
public Animator MyAnimator;
public SharedString DamageTrigger;
public SharedString DeathTrigger;
public GameObject EffectMonster;
public GameObject EffectBoss;
private float HitCDTime=1.4f;//转入硬直的切换行为的时间
private float HitCDTimer=1.4f;
public int Damage;
List<IsHit> Hits = new List<IsHit>();
public List<string> Attack=new List<string>();
// Use this for initialization
public override void OnStart()
{
TakeDamage(Damage);
}
public override TaskStatus OnUpdate()
{
if (HitCDTime > HitCDTimer)
{
HitCDTimer += Time.deltaTime;
if (HitCDTime < HitCDTimer)
return TaskStatus.Success;
else
return TaskStatus.Running;
}
else
{
if (Hits.Count == 0)
Hits = GetComponent<BehaviorTree>().FindTasks<IsHit>();
foreach (IsHit temp in Hits)
{
temp.isHit = false;
}
return TaskStatus.Failure;
}
}
public TaskStatus TakeDamage(int Damage)
{
if (MyState.Hp > 0)
{
MyState.Hp -= Damage;
if (MyState.Hp > 0)
MyAnimator.SetTrigger(DamageTrigger.Value);
else
MyAnimator.SetTrigger(DeathTrigger.Value);
Vector3 position = transform.position;
position.y += 0.5f;
if (transform.tag == "SoulBoss")
GameObject.Instantiate(EffectBoss, position, Quaternion.identity);
else
GameObject.Instantiate(EffectMonster, position, Quaternion.identity);
foreach (string temp in Attack)//这是中断攻击动画的
if (MyAnimator.GetBool(temp))
{
MyAnimator.SetBool(temp, false);
}
if(MyState.Hp<0)
{
StartCoroutine(Hide());
GetComponent<CharacterController>().enabled = false;
SpawnManage.Instance.EnemyListCopy.Remove(gameObject);
}
HitCDTimer = 0;
return TaskStatus.Success;
}
return TaskStatus.Failure;
}
IEnumerator Hide()
{
yield return new WaitForSeconds(1);
gameObject.SetActive(false);
}
}
武器碰撞到怪物产生伤害,用触发检测
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BehaviorDesigner.Runtime;
public class Weapon : MonoBehaviour {
public int Damage { get; set; }
List<IsHit> Hits=new List<IsHit>();
private void OnTriggerEnter(Collider other)
{
if(Player._instance.AttackSign==true)
if (other.tag == "SoulMonster" || other.tag=="SoulBoss")
{
Hits= other.GetComponent<BehaviorTree>().FindTasks<IsHit>();
foreach (IsHit temp in Hits)
{
temp.isHit = true;
}
other.GetComponent<BehaviorTree>().FindTask<IsHit>().TakeDamage(Damage);
Hits.Clear();
}
}
}