美文网首页
Unity中相机的跟随

Unity中相机的跟随

作者: Xbreathes | 来源:发表于2018-11-22 19:36 被阅读0次

1.首先是最简单的一种方法

public class CameraController : MonoBehaviour {

//注意:该脚本挂载在主相机上

    public Transform player;

    private Vector3 offset;

void Start () {

        offset = transform.position- player.position;

    }

void Update () {

        if (player == null)//

        {

            return;

        }

        transform.position = player.position+ setoff;

}

该方法实现了让主角和相机始终保持一定的距离 通过主角移动带动相机移动 从而使主角始终在屏幕的某一个位置上

相关文章

网友评论

      本文标题:Unity中相机的跟随

      本文链接:https://www.haomeiwen.com/subject/lxrrqqtx.html