胜利文本不会消失

时间:2018-04-11 21:07:54

标签: c# unity3d

我正在Unity中创建一个倾斜迷宫游戏,你必须将球倾斜到迷宫中的特定点。现在,我所做的以下代码应该会触发“你赢了!”当球与迷宫中的块相互作用时的文本。问题是,文本根本不会出现。请分析一下,告诉我任何解决问题的方法。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class NewBehaviourScript : MonoBehaviour {



public Text countText;
public Text winText;

private Rigidbody rb;
private int count;



void Start ()
{
    rb = GetComponent<Rigidbody>();
    count = 0;
    countText.text = "Count: " + count.ToString();
    winText.text = "";
}

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.CompareTag("Pick Up"))
    {
        other.gameObject.SetActive(false);
        count = count + 1;
        SetCountText();


    }
}

void SetCountText()

{ 
    countText.text = "Count: " + count.ToString();

    if (count >= 1)

        winText.text = "You Win!";
}

0 个答案:

没有答案