版本: Unity 6 (6000.0)
语言英语
  • C#

Canvas.renderMode

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实会阅读用户提出的每个建议的更改,并在适用的情况下进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请 <a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public RenderMode renderMode;

描述

Canvas 是在世界模式还是覆盖模式下?

//Attach this script to your Canvas GameObject

using UnityEngine;

public class Example : MonoBehaviour { enum RenderModeStates { camera, overlay, world }; RenderModeStates m_RenderModeStates;

Canvas m_Canvas;

// Use this for initialization void Start() { m_Canvas = GetComponent<Canvas>(); }

// Update is called once per frame void Update() { //Press the space key to switch between render mode states if (Input.GetKeyDown(KeyCode.Space)) { ChangeState(); } }

void ChangeState() { switch (m_RenderModeStates) { case RenderModeStates.camera: m_Canvas.renderMode = RenderMode.ScreenSpaceCamera; m_RenderModeStates = RenderModeStates.overlay; break;

case RenderModeStates.overlay: m_Canvas.renderMode = RenderMode.ScreenSpaceOverlay; m_RenderModeStates = RenderModeStates.world; break; case RenderModeStates.world: m_Canvas.renderMode = RenderMode.WorldSpace; m_RenderModeStates = RenderModeStates.camera;

break; } } }