using System.Collections; using System.Collections.Generic; using UnityEngine; public class BehindCamera : MonoBehaviour { //BEGIN C# //VARIABLES public Transform originObject; public Transform lookingCameraTransform; [Range(0f, 1f)] public float sensitivity = 0.4f; Vector3 forwardVectorTowardsCamera; bool cameraLooking; float dotProductResult; void Update() { //EXECUTE THE NEXT FUNCTION INSIDE UPDATE CheckIfCameraIsLooking(); } //FUNCTIONS public void CheckIfCameraIsLooking() { forwardVectorTowardsCamera = (lookingCameraTransform.position - originObject.position).normalized; dotProductResult = Vector3.Dot(lookingCameraTransform.forward, forwardVectorTowardsCamera); if (cameraLooking) { if (dotProductResult > sensitivity) { cameraLooking = false; StartNotLooking(); } } else { if (dotProductResult < -sensitivity) { cameraLooking = true; StartLooking(); } } if (cameraLooking) { PlayerIsLooking(); } else { PlayerIsNotLooking(); } } void StartLooking() { Debug.Log("Camera starts looking"); } void PlayerIsLooking() { Debug.Log("Camera is currently looking"); } void StartNotLooking() { Debug.Log("Camera stops looking"); } void PlayerIsNotLooking() { Debug.Log("Camera is currently not looking"); } //C# ENDS }