Advertisement
Guest User

Untitled

a guest
May 30th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class AI : MonoBehaviour {
  6. public PlayerController Controller;
  7. public bool DoneHome;
  8. public Vector3 MoveVector = Vector3.zero;
  9. public bool GeneratedVector;
  10. public Waypoint CurWayPoint;
  11. public Waypoint LastWayPoint;
  12. public Location CurrentLocation;
  13. public LocationType CurrentActivity;
  14. public List<Waypoint> CurrentPath;
  15. public NavMeshAgent Agent;
  16.  
  17. // Use this for initialization
  18. void Start () {
  19. if(Agent == null)
  20. {
  21. Agent = GetComponent<NavMeshAgent>();
  22. }
  23.  
  24. Agent.baseOffset = -0.05f;
  25. }
  26.  
  27. // Update is called once per frame
  28. void Update ()
  29. {
  30. if (!Controller.CanPlay)
  31. {
  32. if (DoneHome)
  33. {
  34. if (CurrentLocation == null)
  35. {
  36. CurrentActivity = (LocationType)Random.Range(0, 2);
  37. CurrentLocation = GameManager.Instance.FindLocationOfType(CurrentActivity);
  38. }
  39. else
  40. {
  41. Agent.SetDestination(CurrentLocation.transform.position);
  42. Controller.v = Agent.velocity.z;
  43.  
  44. if (Vector3.Distance(transform.position, CurrentLocation.transform.position) < 0.2f)
  45. {
  46. Agent.Stop();
  47. CurrentLocation = null;
  48. }
  49. }
  50. }
  51. else
  52. {
  53. if (Vector3.Distance(transform.position, Controller.LocalCharacter.HomeSpawn.position) > 0.2f)
  54. {
  55. Agent.SetDestination(Controller.LocalCharacter.HomeSpawn.position);
  56. Controller.v = Agent.velocity.z;
  57. }
  58. else
  59. {
  60. DoneHome = true;
  61. Controller.v = 0;
  62. Agent.Stop();
  63. }
  64. }
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement