C#写的U3D相机跟随

来源:互联网 发布:avmoo.com新域名 编辑:程序博客网 时间:2024/06/06 15:43
熟悉c#中。。。
实现的功能是简单的相机的跟随的效果
代码如下:
using UnityEngine; using System.Collections;  public class TargetFollower : MonoBehaviour{   public Transform Target_char;    public float smoothTime = 0.01f;   private Vector3 cameraVelocity = Vector3.zero;      private Camera mainCamera;        void  Awake ()     {    mainCamera = Camera.main;   }   void  Update()   {  transform.position = Vector3.SmoothDamp(transform.position, Target_char.position + new Vector3(0, 0, -5), ref cameraVelocity, smoothTime);   }  }
效果如图,相机会跟随物体移动。修改参数可以调整跟随的速度。
原创粉丝点击