Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- namespace FIMSpace.FLook
- {
- public class FLookAnimator_Demo_NPCPriority1 : MonoBehaviour
- {
- public string ImportantTargetTag = "Player";
- public string NPCTag;
- private FLookAnimator npcLookAnimator;
- private Transform importantTarget;
- private Transform targetInRange;
- // When component is added inside editor, it reads object's tag to be putted in NPCTag variable
- private void Reset()
- {
- NPCTag = gameObject.tag;
- }
- private void Start()
- {
- npcLookAnimator = GetComponent<FLookAnimator>();
- }
- // When someone steps in range
- private void OnTriggerEnter(Collider other)
- {
- if (other.tag == ImportantTargetTag)
- {
- importantTarget = other.transform;
- UpdateLookTarget();
- }
- else
- if (other.tag == NPCTag)
- {
- targetInRange = other.transform;
- UpdateLookTarget();
- }
- }
- // When someone left look at range
- private void OnTriggerExit(Collider other)
- {
- if (other.tag == ImportantTargetTag)
- {
- importantTarget = null;
- UpdateLookTarget();
- }
- else
- if (other.tag == NPCTag)
- {
- targetInRange = null;
- UpdateLookTarget();
- }
- }
- private void UpdateLookTarget()
- {
- // If important target is set, we looking at it (player)
- if (importantTarget)
- npcLookAnimator.ObjectToFollow = importantTarget;
- else
- if (targetInRange)
- npcLookAnimator.ObjectToFollow = targetInRange;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement