Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(197评价)
价格: 4431.00元
关于behavior designer的打断问题
a88148114发起了问答2017-12-16
4
回复
1975
浏览

为什么怪物被主角打中时行为树不会打断后面的操作

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();
            }
    }
}

 

所有回复
  • siki 2017-12-16

    检查一下你的行为树,isHit有没有被设置为true
    先确定是你的行为树的问题,还是你的代码的问题

    还有-4条回复,点击查看
    你还没有登录,请先登录注册
  • siki 2017-12-20

    代码都没问题的话,可能是插件跟unity版本不兼容,要使用跟unity版本相兼容的插件版本

    如果unity使用的版本比较新也要使用新版本的行为树插件

    在插件官网会写每个插件兼容到哪个版本的unity

    • a88148114 2017-12-20

      好像真的是不兼容的问题,换了个新版本就可以了,谢谢siki老师

      (0) 回复
    还有-4条回复,点击查看
    你还没有登录,请先登录注册
发表回复
你还没有登录,请先 登录或 注册!