您的位置:首页 > 移动开发 > Unity3D

噩梦5 camera跟随

2015-07-28 15:59 441 查看


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);

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity3d 教程