Esempio n. 1
0
    private void Update()
    {
        if (nextNode != null)
        {
            if (AutoMove)
            {
                // move towards nextNode
                float step = speed * Time.deltaTime;
                transform.position = Vector3.MoveTowards(transform.position, nextPosition, step);
            }

            UpdatePosition();
            // if at nextNode, activate nextNode and deactive last node
            if (PersonNearTarget(nextNode.position, offset))
            {
                if (nextNode.branches != 0)
                {
                    int nextIndex = Random.Range(0, nextNode.branches);
                    lastNode = nextNode;
                    nextNode = nextNode.nextNode[nextIndex];
                    lastNode.Deactivate(id);
                    nextNode.Activate(id);
                    //update pathManager

                    nextPosition = nextNode.position + new Vector3(Random.Range(-offset, offset),
                                                                   Random.Range(-offset, offset), Random.Range(-offset, offset));
                }
                else // reached end, no more nodes in path
                {
                    lastNode = nextNode;
                    nextNode = null;
                }
            }
        }
    }