Example #1
0
    void OnTriggerEnter(Collider other)
    {
        // Check if we have bumped into the player.
        if (GameplayManager.Instance.CanPlay() && other.GetComponentInParent <PlayerController>())
        {
            // If so we caught the player.
            perception.SetViewConeColor(pursuitColor);
            state = State.Capture;

            // Notify the gameplay manager.
            GameplayManager.Instance.OnPlayerCaught();
        }
    }
Example #2
0
    void Start()
    {
        droneMoveSource    = AudioHelper.CreateAudioSource(gameObject, droneMoveAudio);
        droneAlertSource   = AudioHelper.CreateAudioSource(gameObject, droneAlertAudio);
        dronePursuitSource = AudioHelper.CreateAudioSource(gameObject, dronePursuitAudio);

        // Keep references to commonly accessed components.
        agent      = GetComponent <NavMeshAgent>();
        perception = GetComponentInChildren <AIPerception>();

        // By default, the agent starts in the patrol state.
        perception.SetViewConeColor(normalColor);
        state = State.Patrol;

        // Track the agent's move speed.
        speed = agent.speed;

        // Store the list of waypoints from our patrol path.
        waypoints = new Transform[patrolPath.childCount];
        for (int i = 0; i < waypoints.Length; ++i)
        {
            waypoints[i] = patrolPath.GetChild(i);
        }

        // Loop through all the waypoints and pick the closest one. This is where
        // we should patrol toward first.
        float closestDistance = Vector3.Distance(transform.position, waypoints[0].position);

        for (int i = 1; i < waypoints.Length; ++i)
        {
            float distance = Vector3.Distance(transform.position, waypoints[i].position);
            if (distance < closestDistance)
            {
                closestDistance = distance;
                currentWaypoint = i;
            }
        }

        // Hide the alert icon by default.
        exclamationMark.SetActive(false);
    }
    void Start()
    {
        droneMoveSource = AudioHelper.CreateAudioSource(gameObject, droneMoveAudio);
        droneAlertSource = AudioHelper.CreateAudioSource(gameObject, droneAlertAudio);
        dronePursuitSource = AudioHelper.CreateAudioSource(gameObject, dronePursuitAudio);

        // Keep references to commonly accessed components.
        agent = GetComponent<NavMeshAgent>();
        perception = GetComponentInChildren<AIPerception>();

        // By default, the agent starts in the patrol state.
        perception.SetViewConeColor(normalColor);
        state = State.Patrol;

        // Track the agent's move speed.
        speed = agent.speed;

        // Store the list of waypoints from our patrol path.
        waypoints = new Transform[patrolPath.childCount];
        for (int i = 0; i < waypoints.Length; ++i)
        {
            waypoints[i] = patrolPath.GetChild(i);
        }

        // Loop through all the waypoints and pick the closest one. This is where
        // we should patrol toward first.
        float closestDistance = Vector3.Distance(transform.position, waypoints[0].position);
        for (int i = 1; i < waypoints.Length; ++i)
        {
            float distance = Vector3.Distance(transform.position, waypoints[i].position);
            if (distance < closestDistance)
            {
                closestDistance = distance;
                currentWaypoint = i;
            }
        }

        // Hide the alert icon by default.
        exclamationMark.SetActive(false);
    }