// Use this for initialization
    void Awake()
    {
        //create a tree with just the attack node
        senses = GetComponentInChildren <AIPerceptor>();
        tree   = new BTTree
                 (
            new BTSelector(new List <BTTask>()
        {
            new BTSequence(new List <BTTask>()
            {
                new CheckIfPlayerUnderAttack(),
                new RLFightOrFlight()
            }),
            new FollowPlayerSequence(),
            new Idle()
        }
                           ));

        //setup the blackboard values
        tree.Blackboard = new Blackboard();
        senses          = GetComponentInChildren <AIPerceptor>();
        senses.SetBlackboard(tree.Blackboard);
        tree.Blackboard.SetValue("owner", this.gameObject);
        tree.Blackboard.SetValue("senses", senses);
        if (player)
        {
            tree.Blackboard.SetValue("player", player);
        }
        tree.BeginTree();
    }
    // Use this for initialization
    void Awake()
    {
        tree.Blackboard = new Blackboard();
        senses          = GetComponentInChildren <AIPerceptor>();

        //create the behaviour tree
        tree = new BTTree(
            new BTSelector(new List <BTTask>()
        {
            new Timer(
                new BTSequence(
                    new List <BTTask>()
            {
                new MoveTo(),
                new SelectNextLocation()
            }),
                5f),

            new RLAttack(
                new List <BTTask>()
            {
                new FireballAttack(),
                new WaterAttack(),
                new AirAttack(),
                new EarthAttack()
            })
        }));

        tree.Blackboard.SetValue("owner", this.gameObject);
        tree.Blackboard.SetValue("patrolPoints", GetComponent <Patrol>().GetPatrolPoints());
        tree.Blackboard.SetValue("moveToPos", GetComponent <Patrol>().GetPatrolPoints()[0].transform.position);
        tree.Blackboard.SetValue("distanceToArrival", 0.5f);
        tree.Blackboard.SetValue("senses", senses);
        tree.BeginTree();
    }
 // Update is called once per frame
 void Update()
 {
     if (Time.timeScale != 0.0f)
     {
         if (tree.GetStatus() == StatusValue.RUNNING)
         {
             tree.Tick();
         }
         if (tree.GetStatus() != StatusValue.RUNNING)
         {
             tree.BeginTree();
         }
     }
     UpdateDebugText();
 }
 // Update is called once per frame
 void Update()
 {
     //Debug.Log(tree.GetStatus().ToString());
     if (Time.timeScale != 0.0f)
     {
         tree.Blackboard.SetValue("MyHealthAsPercentage", GetHealthAsPercentage());
         if (tree.GetStatus() == StatusValue.RUNNING)
         {
             tree.Tick();
         }
         //restart the tree when all of the nodes have returned
         if (tree.GetStatus() != StatusValue.RUNNING)
         {
             tree.BeginTree();
         }
     }
     UpdateDebugText();
 }