using UnityEngine;
public class FollowTargetCamera : MonoBehaviour
{
public Transform Target;
public float PositionFolowForce = 5f;
public float RotationFolowForce = 5f;
public Vector3[] directions = new Vector3[] { Vector3.forward, Vector3.back
, Vector3.left, Vector3.right };
private int index = 0;
private Vector3 vector = new Vector3(0, 0, 0);
private Vector3 dir = new Vector3(0, 0, 0);
void Start()
{
}
void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.V))
{
if (++index == directions.Length)
index = 0;
vector = directions[index];
dir = Target.rotation * directions[index];
}
dir.y = 0f;
if (dir.magnitude > 0f) vector = dir / dir.magnitude;
transform.position = Vector3.Lerp(transform.position, Target.position, PositionFolowForce * Time.deltaTime);
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(vector), RotationFolowForce * Time.deltaTime);
}
}
Sometimes i click/press on the key V once or twice to move to the next view. Sometimes i need to click/press 3 times in a row to change a view. I want it to change a view each one click.