Exemplo n.º 1
0
Arquivo: NPC.cs Projeto: zkajota/Unity
    private void DoQueue()
    {
        //check if any item is in Queue
        if (queue.Count != 0)
        {
            ActionClass currentAction = queue[0];
            if (target == null)
            {
                //find which fountain to go to. If all are taken shuffle Queue.
                target = currentAction.FindActionplace(area);
                if (target == null)
                {
                    if (queue.Count > 1)
                    {
                        ShuffleQueue();
                    }
                }
            }
            if (target != null)
            {
                //check if close to correct fountain, and fulfill need
                if (Vector3.Distance(transform.position, target.position) < 1.0f)
                {
                    foreach (var need in needs)
                    {
                        if (need.name == currentAction.forNeed)
                        {
                            bool finished = currentAction.FulfillNeed(need, true, target);
                            gameObject.GetComponent <Renderer>().material.SetColor("_Color", currentAction.color);
                            target.GetComponent <ActionObjectScript>().isTaken = true;

                            //remove from queue
                            if (finished == true)
                            {
                                need.queued = false;
                                target.GetComponent <ActionObjectScript>().isTaken = false;

                                target = null;
                                queue.RemoveAt(0);
                                gameObject.GetComponent <Renderer>().material.SetColor("_Color", Color.white);
                                UI_Script.instance.CreateActionsUI();
                            }
                        }
                    }
                }
            }
        }
    }