using System.Collections;using System.Collections.Generic;using UnityEngine;public class FirstCamera : MonoBehaviour { public Transform target; public float distance; public float targetHeight; public float PitchAngle; private float x = 0.0f; private float y = 0.0f; // Use this for initialization void Start () { var angles = transform.eulerAngles; x = angles.x; y = angles.y; } // Update is called once per frame void LateUpdate() { if (!target) return; y = target.eulerAngles.y; // ROTATE CAMERA: Quaternion rotation = Quaternion.Euler(x - PitchAngle, y, 0); transform.rotation = rotation; // POSITION CAMERA: Vector3 position = target.position - (rotation * Vector3.forward * distance + new Vector3(0, -targetHeight, 0)); transform.position = position; }}创建一个摄像机,使其成为物体的子物体,将此脚本拖到摄像机下,可以在摄像机的Inspector面板如下图,修改distince和Target Height调整摄像机角度位置。
unity实现第一视角的跟随物体运动
最新推荐文章于 2025-03-04 16:54:32 发布