Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- using Random=UnityEngine.Random;
- public class PatrikAI : MonoBehaviour
- {
- public GameObject player;
- public Transform eyes;
- public float speed = 3f;
- public NavMeshAgent agent;
- public GameObject[] wanderLocations;
- public bool isHunting;
- public bool pickOne = true;
- void Update()
- {
- agent.speed = speed;
- RaycastHit hit;
- Vector3 fromPosition = eyes.transform.position;
- Vector3 toPosition = player.transform.position;
- Vector3 direction = toPosition - fromPosition;
- if (Physics.Raycast(eyes.transform.position, direction, out hit, Mathf.Infinity))
- {
- if(hit.transform.tag == "Player")
- {
- Hunt();
- }
- else if(player.GetComponent<PlayerActions>().isHidden == true)
- {
- if(isHunting == true)
- {
- Hunt();
- }
- else
- {
- Hear();
- }
- }
- else
- {
- Hear();
- }
- }
- }
- void Follow(){
- isHunting = false;
- speed = 4f;
- agent.destination = player.transform.position;
- }
- void Hunt(){
- isHunting = true;
- speed = 8f;
- agent.destination = player.transform.position;
- }
- void WanderOff(){
- speed = 4f;
- if(pickOne == true)
- {
- agent.destination = wanderLocations[Random.Range(0, wanderLocations.Length - 1)].transform.position;
- pickOne = false;
- }
- if(agent.remainingDistance < 3f && pickOne == false){
- agent.destination = wanderLocations[Random.Range(0, wanderLocations.Length - 1)].transform.position;
- pickOne = true;
- }
- }
- void Hear(){
- isHunting = false;
- GameObject[] noice = GameObject.FindGameObjectsWithTag("Noice");
- if(noice.Length == 2){
- Destroy(noice[0]);
- }
- if(noice.Length > 0){
- speed = 8f;
- agent.destination = noice[noice.Length - 1].transform.position;
- }
- else
- {
- WanderOff();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement