我希望能够做到这一点,以便在满足特定条件时,“文本”值将更改为“您赢了”,而不是继续计数该值。因此,如果它们超过100分或等于100分,那么它将打印出您的胜利。
尝试比较String和Text,以及String和String与string.Compare。
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreManager : MonoBehaviour
{
public Text scoreText;
public int score;
private Board board;
// Start is called before the first frame update
void Start()
{
board = FindObjectOfType<Board>();
}
// Update is called once per frame
void Update()
{
scoreText.text = score.ToString();
}
public void IncreaseScore(int increase)
{
score += increase;
}
}
答案 0 :(得分:1)
只需执行以下操作:
void Update()
{
scoreText.text = (score < 100) ? score.ToString() : "You Win";
}