简体   繁体   English

Unity,如何获取相机角度宽度

[英]Unity, how to get Camera angle Width

I'm making game that must set target number on all enemy on screen. 我正在制作必须在屏幕上所有敌人上设置目标编号的游戏。
I FAIL TO FIND function like IsInsideCameraView(gameObject) 我无法找到IsInsideCameraView(gameObject)之类的函数

Now I'm trying to scan area that camera looks. 现在,我正在尝试扫描相机看起来的区域。 For this, I need Camera angle width, angle hight. 为此,我需要摄影机角度宽度,角度hight。 As described in this emage (My reputation is not enough to show image directly) 如本照片中所述 (我的声誉不足以直接显示图像)

My question is similer to this question, How to get angles value of perspective camera in Three.js? 我的问题类似于这个问题, 如何在Three.js中获取透视相机的角度值? but for Unity. 但对于Unity。

If you know 如果你知道的话
HOW TO CALCULATE CAMERA WIDTH&HEIGHT (following screen size when unity starts)or 如何计算相机的宽度和高度(统一开始时遵循屏幕尺寸)或
IS THERE GOOD FUNTIONS LIKE IsInsideCameraView(Camera, gameObject) 有像IsInsideCameraView(Camera,gameObject)这样的好功能吗?
any answers will be welcomed. 任何答案都将受到欢迎。

[Untested. [未经测试。 Javascript] You can use renderer.isVisible to determine if the object is within the camera frustum. 您可以使用renderer.isVisible确定对象是否在相机视锥中。

I FAIL TO FIND function like IsInsideCameraView(gameObject) 我无法找到IsInsideCameraView(gameObject)之类的函数

You can use: 您可以使用:

object.Renderer.isVisible

...to check if the object is visible in any camera . ...以检查对象是否在任何相机中可见。

To test for a specific camera, use: 要测试特定的相机,请使用:

Vector3 screenPos = camera.WorldToScreenPoint(target.position);

Then check if X and Y coordinates are between (0,0) and Screen.width , Screen.height . 然后检查是否XY坐标为(0,0)之间Screen.widthScreen.height

HOW TO CALCULATE CAMERA WIDTH&HEIGHT 如何计算相机的宽度和高度

That's what Camera.pixelWidth and Camera.pixelHeight are for or you can use Screen.width , Screen.height for cameras that represent the entire screen. 这就是Camera.pixelWidthCamera.pixelHeight是或者你可以使用Screen.widthScreen.height为代表的整个屏幕的相机。

Anyway, that's arguably a XY problem, refer to the beginning of my answer for direct solution. 无论如何,这可以说是XY问题,请参阅我的答案的开头以寻求直接解决方案。

Tell me more 告诉我更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM