Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.AI;
- using UnityEngine.UI;
- public class PatrolScript : MonoBehaviour
- {
- public NavMeshAgent cop;
- public GameObject Player;
- public float FollowDistance = 20.0f;
- public Transform[] patrolPoints;
- private int currentPoint = 0;
- public Vector3 jailPos;
- public GameObject eye;
- public NavMeshAgent doggy;//
- void Start()
- {
- MoveToNextPoint();
- }
- void Update()
- {
- float dist = Vector3.Distance(Player.transform.position, cop.transform.position);
- float dogDist = Vector3.Distance(doggy.transform.position, cop.transform.position);//
- bool patrol = false;
- bool runAway = false;//
- bool follow = (dist < FollowDistance && !runAway);
- if (follow)
- {
- cop.SetDestination(Player.transform.position);
- eye.SetActive(true);
- if(dist <= 1.05f)
- {
- sendToJail();
- }
- }
- patrol = !follow && !runAway;
- if (!follow && !patrol && !runAway)//
- {
- eye.SetActive(false);
- patrol = true;
- // cop.SetDestination(patrolPoints[currentPoint].position);
- }
- if (patrol)
- {
- eye.SetActive(false);
- if (!cop.pathPending && cop.remainingDistance < 0.5f)
- {
- MoveToNextPoint();
- }
- }
- if (runAway)//
- {
- patrol = false;
- follow = false;
- Vector3 moveDir = cop.transform.position - doggy.transform.position;
- transform.Translate(moveDir.normalized * 30 * Time.deltaTime);
- if (dogDist > 25 && dist > FollowDistance)
- {
- patrol = true;
- runAway = false;
- follow = false;
- }else if ( dogDist > FollowDistance) {
- patrol = false;
- runAway = false;
- follow = true;
- }
- }
- }
- void MoveToNextPoint()
- {
- cop.destination = patrolPoints[currentPoint].position;
- currentPoint++;
- if (currentPoint >= patrolPoints.Length)
- {
- currentPoint = 0;
- }
- }
- void sendToJail()
- {
- Player.transform.position = jailPos;
- PlayerPrefs.SetInt("money", PlayerPrefs.GetInt("money") - 100);
- PlayerPrefs.SetInt("points", 0);
- //clear inv
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement