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 dog : MonoBehaviour
- {
- public NavMeshAgent doggy;
- public GameObject Player;
- public float sitDistance = 7.0f;
- public NavMeshAgent cop;
- void Update()
- {
- float dist = Vector3.Distance(Player.transform.position, doggy.transform.position);
- bool sit = false;////////does this all gota be in update? optomize?
- float opDist = Vector3.Distance(cop.transform.position, doggy.transform.position);
- bool chase = false;
- bool follow = (dist > sitDistance && !chase);
- if (follow)
- {
- doggy.SetDestination(Player.transform.position);
- }
- else if (!chase)
- {
- sit = true;
- }
- if (sit)
- {
- doggy.SetDestination(doggy.transform.position);
- }
- // sit = !follow;
- if (opDist < 10)
- {
- chase = true;
- follow = false;
- sit = false;
- }
- if (chase)
- {
- doggy.SetDestination(cop.transform.position);
- if (dist > 10 && !sit){
- chase = false;
- follow = true;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment