using UnityEngine;
using System.Collections;
public class cam : MonoBehaviour {
public Transform target;
public float distance = 8;
public float h;
public float v;
float speed = 200;
void Start ()
{
Fn();
}
void Update ()
{
if (Input.GetMouseButton(0))
{
h += Input.GetAxis("Mouse X") * speed * Time.deltaTime;
v -= Input.GetAxis("Mouse Y") * speed * Time.deltaTime;
v = Mathf.Clamp(v, 0, 80);
Fn();
}
}
void Fn()
{
Quaternion q = Quaternion.Euler(v, h, 0);
transform.rotation = q;
Vector3 dir = q * new Vector3(0, 0, -distance);
transform.position = target.position + dir;
}
}
Unity_简单的摄像机绕物体旋转
最新推荐文章于 2024-04-26 15:30:33 发布