我到处都看到使用Camera.main
是不好的做法,我们不应该使用它。那么,获取主相机对象的最佳做法是什么?
您应该在该摄像机的整个生命周期中存储一次对每个摄像机的引用,然后在其余的代码中使用该存储的参考。例如:
// Reference initialization
public Camera mainCamera;
// Game code, executed once per frame or more
void Update()
{
Vector3 pos = mainCamera.transform.position;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句