Demo entry 6746728

TPCamera

   

Submitted by xmh on May 30, 2018 at 19:00
Language: C#. Code size: 666 Bytes.

public class OrbitCamera : MonoBehaviour
{
    [SerializeField] private Transform target;
    public float rotSpeed = 1.5f;
    private float _rotY;
    private Vector3 _offset;
	void Start ()
	{
	    _rotY = transform.eulerAngles.y;
	    _offset = target.position - transform.position;
	}
	void LateUpdate ()
	{
	    float horInput = Input.GetAxis("Horizontal");
	    if (horInput != 0) _rotY += horInput * rotSpeed;
        else _rotY += Input.GetAxis("Mouse X") * rotSpeed * 3;
        Quaternion rotation = Quaternion.Euler(0, _rotY, 0);
	    transform.position = target.position - (rotation * _offset);
        transform.LookAt(target);
	}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).