码迷,mamicode.com
首页 > 其他好文 > 详细

噩梦5 camera跟随

时间:2015-07-28 18:50:47      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:unity3d   教程   

技术分享

namespace CompleteProject
{
    public class CameraFollow : MonoBehaviour
    {
        public Transform target;            // The position that that camera will be following.
        public float smoothing = 5f;        // The speed with which the camera will be following.




        Vector3 offset;                     // The initial offset from the target.




        void Start ()
        {
            // Calculate the initial offset.
            offset = transform.position - target.position;
        }




        void FixedUpdate ()
        {
            // Create a postion the camera is aiming for based on the offset from the target.
            Vector3 targetCamPos = target.position + offset;


            // Smoothly interpolate between the camera‘s current position and it‘s target position.
            transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
        }
    }
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

噩梦5 camera跟随

标签:unity3d   教程   

原文地址:http://blog.csdn.net/haifeng619/article/details/47106597

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!