Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.AI;
- public class npcSleeper : npcBase
- {
- private NavMeshAgent myNav;
- private enum mode { sleeping, hunting, frozen };
- private mode myMode;
- private float patience = 3; // Aggro grace in seconds.
- private float patienceCounter;
- private Transform player;
- private float killRange = 0.3f;
- private float litThreshold = 0.1f;
- private RaycastHit hitInfo;
- public override void Start()
- {
- base.Start();
- myNav = GetComponent<NavMeshAgent>();
- myMode = mode.sleeping;
- player = VRTK.VRTK_DeviceFinder.HeadsetTransform();
- }
- public override void Update()
- {
- base.Start();
- switch (myMode)
- {
- case mode.sleeping:
- doSleeping();
- break;
- case mode.hunting:
- doHunting();
- break;
- case mode.frozen:
- doFrozen();
- break;
- }
- }
- private void doSleeping()
- {
- if (lit > litThreshold)
- {
- patienceCounter += Time.deltaTime;
- }
- if (patienceCounter > patience)
- {
- myMode = mode.hunting;
- }
- }
- private void doHunting()
- {
- if ((transform.position - player.position).magnitude > killRange)
- {
- if (Physics.Raycast(transform.position, (player.position - transform.position), out hitInfo, killRange, ~LayerMask.GetMask("powerBeam", "lightBeam")))
- {
- if (hitInfo.transform == player)
- {
- Debug.Log("This kills the player");
- }
- }
- }
- if ((myNav.isOnNavMesh) && ((myNav.destination - player.position).magnitude > killRange))
- {
- myNav.SetDestination(player.position);
- }
- if (lit > litThreshold)
- {
- myMode = mode.frozen;
- }
- }
- private void doFrozen()
- {
- if (lit < litThreshold)
- {
- myMode = mode.hunting;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement