unity实现第一视角的跟随物体运动
using System.Collections;using System.Collections.Generic;using UnityEngine;public class FirstCamera : MonoBehaviour { public Transform target; public float distance; public float targetHeight; public
·
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调整摄像机角度位置。
更多推荐



所有评论(0)