VR中的OnGUI没有显示

时间:2015-08-28 12:34:46

标签: user-interface unity3d oculus virtual-reality

我已经包含了以下一行,以便在场景的左上角显示一个简单的timer,当然,当我勾选Virtual Reality Supported复选框并放上Oculus时裂痕,它消失了。

void OnGUI()
{
    GUI.Label(new Rect(10, 10, 100, 20), Time.time.ToString());
}

我错过了什么?我还应该做些什么来解决这个问题?

2 个答案:

答案 0 :(得分:3)

OnGUI在VR中不起作用。您必须使用world space canvas UI

答案 1 :(得分:3)

OnGUI()在VR中不起作用。而是使用世界空间画布UI。

我为Gear-VR做了以下工作。

向场景添加画布(或包含" Canvas"组件的其他UI元素)。将渲染模式设置为世界空间。这可以在UI Canvas对象的渲染模式下拉列表中找到:

enter image description here

我最终选择了800 x 600画布。

对于计时器本身,我使用了Time.deltaTime

这是我的整个PlayerController脚本:

void Start ()
{
 timeLeft = 5;
 rb = GetComponent<Rigidbody>();
 count = 0;
 winText.text = "";
 SetCountText ();
}

void Update() {
 if (gameOver) {
    if (Input.GetMouseButtonDown(0)) {
        Application.LoadLevel(0);
    }
} else {
    timeLeft -= Time.deltaTime;
    timerText.text = timeLeft.ToString("0.00");
    if (timeLeft < 0) {
        winner = false;
        GameOver(winner);
    }
 }
}
void GameOver(bool winner) {
 gameOver = true;
 timerText.text = "-- --";
 string tryAgainString = "Tap the touch pad to try again.";
 if (!winner) { // case A
    winText.text = "Time's up.\n" + tryAgainString;
 }
 if (winner) { // case B
    winText.text = "Well played!\n" + tryAgainString;
 }
}

void FixedUpdate ()
{
 float moveHorizontal = Input.GetAxis ("Mouse X");
 float moveVertical = Input.GetAxis ("Mouse Y"); 
 Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);    
 rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other) 
{
 if (other.gameObject.CompareTag ( "Pick Up")){
    other.gameObject.SetActive (false);
    count = count + 1;
    SetCountText ();
    if (!gameOver) {
        timeLeft += 3;
    }
 }
}   
void SetCountText ()
{
 if (!gameOver) {
    countText.text = "Count: " + count.ToString ();
 }
 if (count >= 12) {
    winner = true;
    GameOver(winner);
 }
}