Guest User

Untitled

a guest
Jan 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5. using UnityEngine.UI;
  6.  
  7. public class dog : MonoBehaviour
  8. {
  9. public NavMeshAgent doggy;
  10. public GameObject Player;
  11. public float sitDistance = 7.0f;
  12. public NavMeshAgent cop;
  13.  
  14.  
  15. void Update()
  16. {
  17. float dist = Vector3.Distance(Player.transform.position, doggy.transform.position);
  18. bool sit = false;////////does this all gota be in update? optomize?
  19. float opDist = Vector3.Distance(cop.transform.position, doggy.transform.position);
  20. bool chase = false;
  21. bool follow = (dist > sitDistance && !chase);
  22. if (follow)
  23. {
  24. doggy.SetDestination(Player.transform.position);
  25. }
  26. else if (!chase)
  27. {
  28. sit = true;
  29. }
  30. if (sit)
  31. {
  32. doggy.SetDestination(doggy.transform.position);
  33. }
  34. // sit = !follow;
  35. if (opDist < 10)
  36. {
  37. chase = true;
  38. follow = false;
  39. sit = false;
  40. }
  41. if (chase)
  42. {
  43. doggy.SetDestination(cop.transform.position);
  44. if (dist > 10 && !sit){
  45. chase = false;
  46. follow = true;
  47. }
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment