unity 相机围绕物体旋转脚本

1.在场景新建一个C#脚本 例如(命名为cameraHandle) 打开cameraHandle.cs 添加以下代码

public class cameraHandle: MonoBehaviour
{

    [Header("查看目标")]  public GameObject target; //相机需要围绕的目标 在unity里面吧物体直接拖进去
    [Header("控制相机围绕速度")]  public float rotatingSpeed = 5f;
    void Start()
    {
        
    }
    void LateUpdate()
    {
        if (target)
        {
            transform.RotateAround(target.transform.position, Vector3.up, rotatingSpeed * Time.deltaTime);
        }
    }
}

2.上面代码中的查看目标可以在unity里面直接拖入
在这里插入图片描述
3.保存、运行

猜你喜欢

转载自blog.csdn.net/qq_42266800/article/details/130312936
今日推荐