UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Camera.pixelHeight
# [Camera](https://docs.unity3d.com/cn/2019.4/ScriptReference/Camera.html).pixelHeight public int **pixelHeight** ; ## 描述 摄像机的像素高度(不考虑动态分辨率缩放)。(只读) 用于返回摄像机视口的高度(以像素为单位)。(只读) ``` //Attach this script to an empty GameObject //Create a new Camera (Create>Camera) and position it appropriately. Attach it to the Second Camera field in the Inspector of the GameObject //Press the space key to enable and disable the second Camera using UnityEngine; public class Example : MonoBehaviour { //Attach a new Camera in the Inspector window public Camera m_SecondCamera; //This is set as the main Camera in this script Camera m_FirstCamera; void Start() { //Disable the second Camera m_SecondCamera.enabled = false; //Set where to place the second Camera along with its width and height m_SecondCamera.pixelRect = new Rect(0, 0, 400, 200); //Set the first Camera as the main Camera m_FirstCamera = Camera.main; } void Update() { //Press the space key to toggle the second Camera and output camera pixel width and height if (Input.GetKeyDown(KeyCode.Space)) { //Check if the second camera is enabled yet if (!m_SecondCamera.enabled) { //Toggle the second Camera and output the second Camera's details ToggleCamera(m_SecondCamera, m_SecondCamera); } else { //Toggle the second Camera and output the first Camera's details ToggleCamera(m_SecondCamera, m_FirstCamera); } } } //Toggle the Camera and output the Camera specified void ToggleCamera(Camera cameraToggle, Camera cameraOutput) { //Set Camera on and off cameraToggle.enabled = !cameraToggle.enabled; //Output the Camera's new Pixel width Debug.Log("Pixel width :" + cameraOutput.pixelWidth + " Pixel height : " + cameraOutput.pixelHeight); } } ```
da
2022年5月24日 10:22
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码