Skip to content

Instantly share code, notes, and snippets.

@romainPechot
Created December 19, 2016 23:11
Show Gist options
  • Save romainPechot/8b231fbca0b2d7ce52d474a5fd5a177b to your computer and use it in GitHub Desktop.
Save romainPechot/8b231fbca0b2d7ce52d474a5fd5a177b to your computer and use it in GitHub Desktop.
3rd Camera Scripts
using UnityEngine;
public class OrbitPivot : MonoBehaviour
{
public float sensitivity = 10f;
private void LateUpdate()
{
if(Input.GetMouseButton(1))
{
transform.Rotate(Vector3.left * Input.GetAxis("Mouse Y") * Time.deltaTime * sensitivity, Space.Self);
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * sensitivity, Space.World);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
}
using UnityEngine;
public class TransformFollower : MonoBehaviour
{
[SerializeField]
private Transform target;
[SerializeField]
private Vector3 offsetPosition;
[SerializeField]
private Space offsetPositionSpace = Space.Self;
private void LateUpdate()
{
if(offsetPositionSpace == Space.Self)
{
transform.position = target.TransformPoint(offsetPosition);
}
else
{
transform.position = target.position + offsetPosition;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment