Advertisement
GamerRO

Welp

Aug 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5.  
  6. public class GoIntoShop : MonoBehaviour {
  7.  
  8. public Transform Waypoint;
  9.  
  10. public NavMeshAgent Agent;
  11.  
  12. public Animator anim;
  13.  
  14. public NPCSpawner nspawner;
  15.  
  16. public Doors drs;
  17.  
  18. public bool moveToDestination;
  19.  
  20. public float distanceToStop;
  21.  
  22. public void Start()
  23. {
  24. distanceToStop = 0.5f;
  25. Agent = GetComponent<NavMeshAgent>();
  26. Agent.updateRotation = true;
  27. Agent.autoBraking = true;
  28. moveToDestination = true;
  29. Agent.isStopped = false;
  30. nspawner = transform.parent.GetComponent<NPCSpawner>();
  31. drs = nspawner.drs;
  32. Agent.height = 0.5f;
  33. Agent.baseOffset = 0f;
  34. }
  35.  
  36. void Update()
  37. {
  38. if (moveToDestination == true)
  39. {
  40. Agent.isStopped = false;
  41. Agent.updateRotation = true;
  42.  
  43. float DistancetoWay = Vector3.Distance(transform.position, Waypoint.position);
  44.  
  45. if (DistancetoWay < distanceToStop)
  46. {
  47. anim.SetFloat("Speed_f", 0f);
  48. moveToDestination = false;
  49. }
  50. } else
  51. {
  52. anim.SetFloat("Speed_f", 0f);
  53. Agent.isStopped = true;
  54. Agent.updateRotation = false;
  55. }
  56.  
  57.  
  58. float DistancetoWay2 = Vector3.Distance(transform.position, Waypoint.position);
  59.  
  60. if (DistancetoWay2 > distanceToStop)
  61. {
  62. anim.SetFloat("Speed_f", 0.2f);
  63. moveToDestination = true;
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement