Unity中获得Camera的信息

在其他脚本中如果想获得Main Camera的信息可以使用如下的代码

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

public class TestCubeStability : MonoBehaviour
{
    public GameObject mainCamera;
    // Start is called before the first frame update
    void Start()
    {
        mainCamera = GameObject.Find("Main Camera");
    }

    // Update is called once per frame
    void Update()
    {
        //Vector3 Cam_Pos = mainCamera.transform.position;
    }
}

上述代码先定义了一个mainCamera的GameObject,然后再start函数中进行初始化。之后可以在Update中每帧获得一次相机的参数,当然你也可以获得其他的相机参数

你可能感兴趣的:(unity,c#,游戏引擎)