Exemplo n.º 1
0
    public NodeState EvaluateTree()
    {
        NodeState state = initialNode.Evaluate();

        if (state != NodeState.RUNNING)
        {
            ResetNodes();
        }
        return(state);
    }
    //the update function called every frame
    public override void OnUpdate()
    {
        //if the characters health is above 0 the behaviour tree will run
        //otherwise the charcater is considered "Dead"
        if (currentHealth > 0)
        {
            Transitions();
            detectObjects();

            switch (m_state)
            {
            case EnemyState.Attack:
            {
                attackTopNode.Evaluate();
                break;
            }

            case EnemyState.Chase:
            {
                chaseTopNode.Evaluate();
                break;
            }

            case EnemyState.Cover:
            {
                coverTopNode.Evaluate();
                break;
            }

            case EnemyState.Wander:
            {
                WanderTopNode.Evaluate();
                break;
            }

            default:
            {
                gameObject.GetComponent <SpriteRenderer>().color = new Color(255, 0, 0, 10);
                break;
            }
            }
        }
        else
        {
            gameObject.GetComponent <SpriteRenderer>().color = new Color(0, 0, 255, 10);
        }
    }
Exemplo n.º 3
0
    //the update function called every frame
    public override void OnUpdate()
    {
        //if the characters health is above 0 the behaviour tree will run
        //otherwise the charcater is considered "Dead"
        if (currentHealth > 0)
        {
            detectObjects();

            topNode.Evaluate();

            if (topNode.GetNodeState() == NodeState.Failure)
            {
                gameObject.GetComponent <SpriteRenderer>().color = new Color(255, 0, 0, 10);
            }
        }
        else
        {
            gameObject.GetComponent <SpriteRenderer>().color = new Color(0, 0, 255, 10);
        }
    }