Survival Shooter 学习

 

Survival Shooter 学习

using UnityEngine;
using System.Collections;

namespace CompleteProject
{
    /// <summary>
    /// 摄像机跟随
    /// </summary>
    public class CameraFollow : MonoBehaviour
    {
        /// <summary>
        /// 摄像机跟随的目标
        /// </summary>
        public Transform target;            
        /// <summary>
        /// 相机的移动速度
        /// </summary>
        public float smoothing = 5f;        

        /// <summary>
        /// 摄像机相对于目标的偏移
        /// </summary>
        Vector3 offset;                     


        void Start ()
        {
            //计算偏移
            offset = transform.position - target.position;
        }


        void FixedUpdate ()
        {
            //计算相机要移动到的位置
            Vector3 targetCamPos = target.position + offset;

            //移动相机
            transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
        }
    }
}
CameraFollow

相关文章:

  • 2021-12-04
  • 2021-08-05
  • 2022-12-23
  • 2021-07-16
  • 2021-06-08
  • 2022-03-02
  • 2021-07-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-01
  • 2021-04-15
  • 2021-08-14
  • 2021-08-30
  • 2021-05-14
相关资源
相似解决方案