unity开发案例R0llABall(3)之相机设置

设置相机跟随思路:首先调整好相机的位置,求出相机跟玩家之间的距离差。之后新建脚本代码,只要让相机的位置一直保持着小球位置+位置差即可。

具体执行过程如下:

新建一个C#脚本文件,命名为CamFollow.接着把他挂载在摄像机上。

在vs中打开该游戏脚本,编写如下代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class player_move : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
       Rigidbody rd= GetComponent<Rigidbody>();
        rd.AddForce(new Vector3(h, 0, v)*10);



    }
}

猜你喜欢

转载自blog.csdn.net/qq_51196701/article/details/123020207