As you can see in the video, I have limited my flashlight so that it does not go off-screen. What i want to do with this is when my flashlight reaches the edge, I want the player to rotate as if he was looking. Here are my scripts if you need them:
My flashlight Script:
using UnityEngine;
using System.Collections;
public class FlashlightTurn : MonoBehaviour {
public float lookSensitivity;
private float yRotation;
private float xRotation;
private float currentYRotation;
private float currentXRotation;
private float yRotationV;
private float xRotationV;
public float lookSmoothDamp;
private Quaternion lookForward;
public float lookSpeed;
public Transform camera;
private Vector3 lookLeftLimit;
void Start () {
lookForward = transform.rotation;
lookLeftLimit = new Vector3(0,130,0);
}
void Update () {
if (!Input.anyKey)
{
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
xRotation = Mathf.Clamp(xRotation, -30, 30);
yRotation = Mathf.Clamp(yRotation, -50, 30);
currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, ref xRotationV, lookSmoothDamp);
currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, ref yRotationV, lookSmoothDamp);
transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0);
}
if(Input.GetKey("w") || Input.GetKey("s") || Input.GetKey("a") || Input.GetKey("d"))
transform.localRotation = Quaternion.Lerp(transform.localRotation, lookForward, lookSpeed * Time.deltaTime);
if (transform.localEulerAngles == lookLeftLimit) {
xRotation += Input.GetAxis("Mouse Y") * lookSensitivity;
transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0);
}
}
}