Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3.  
  4. public class npcSleeper : npcBase
  5. {
  6. private NavMeshAgent myNav;
  7. private enum mode { sleeping, hunting, frozen };
  8. private mode myMode;
  9. private float patience = 3; // Aggro grace in seconds.
  10. private float patienceCounter;
  11. private Transform player;
  12. private float killRange = 0.3f;
  13. private float litThreshold = 0.1f;
  14. private RaycastHit hitInfo;
  15.  
  16. public override void Start()
  17. {
  18. base.Start();
  19. myNav = GetComponent<NavMeshAgent>();
  20. myMode = mode.sleeping;
  21. player = VRTK.VRTK_DeviceFinder.HeadsetTransform();
  22. }
  23.  
  24. public override void Update()
  25. {
  26. base.Start();
  27.  
  28. switch (myMode)
  29. {
  30. case mode.sleeping:
  31. doSleeping();
  32. break;
  33. case mode.hunting:
  34. doHunting();
  35. break;
  36. case mode.frozen:
  37. doFrozen();
  38. break;
  39. }
  40. }
  41. private void doSleeping()
  42. {
  43. if (lit > litThreshold)
  44. {
  45. patienceCounter += Time.deltaTime;
  46. }
  47. if (patienceCounter > patience)
  48. {
  49. myMode = mode.hunting;
  50. }
  51. }
  52.  
  53. private void doHunting()
  54. {
  55. if ((transform.position - player.position).magnitude > killRange)
  56. {
  57. if (Physics.Raycast(transform.position, (player.position - transform.position), out hitInfo, killRange, ~LayerMask.GetMask("powerBeam", "lightBeam")))
  58. {
  59. if (hitInfo.transform == player)
  60. {
  61. Debug.Log("This kills the player");
  62. }
  63. }
  64. }
  65. if ((myNav.isOnNavMesh) && ((myNav.destination - player.position).magnitude > killRange))
  66. {
  67. myNav.SetDestination(player.position);
  68. }
  69. if (lit > litThreshold)
  70. {
  71. myMode = mode.frozen;
  72. }
  73. }
  74. private void doFrozen()
  75. {
  76. if (lit < litThreshold)
  77. {
  78. myMode = mode.hunting;
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement