예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (completed)
        {
            return;                                          // Return early if hidden once
        }
        if (hideBehaviour.getNearbyHidingSpots().Count == 0) // If no hiding spots are within range, move to location
        {
            directionVector = hidingSpotTransform.position - transform.position;
        }
        else if (!hideBehaviour.isHidden()) // If in range, and not hidden, get in closest
        {
            hideBehaviour.hide(hideBehaviour.getClosestHidingSpot());

            if (hideBehaviour.isHidden())
            {
                completed = true;
            }
        }

        base.Update();
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (waitTime > 0.0f && currentWaitTime < waitTime) // If the agent needs to wait and has not yet finished waiting,
        {
            currentWaitTime += Time.deltaTime;             // Increase time
            return;
        }

        if (completed)
        {
            return;                                          // Return early if demo completed
        }
        if (hideBehaviour.getNearbyHidingSpots().Count == 0) // If no hiding spots are within range, move to location
        {
            directionVector = hidingSpotTransform.position - transform.position;
        }
        else if (!completed) // If in range
        {
            HidingSpot hidingSpot = hideBehaviour.getClosestHidingSpot();
            GameObject foundTarget;

            if (target == null)                    // If no target
            {
                foundTarget = hidingSpot.search(); // Search the hiding spot for the latest entrant
            }
            else
            {
                foundTarget = hidingSpot.search(target); // Search the hiding spot for the target
            }
            if (foundTarget != null)                     // If a target has been found
            {
                hidingSpot.forceLeave(foundTarget);      // Force the target to leave
                completed = true;
            }
        }

        base.Update();
    }