我希望能够这样做,当满足某个条件时,文本值将更改为“您赢了”,而不是继续计算该值。因此,如果他们超过100分或等于100分,那么它将打印您获胜。
已尝试将字符串和文本以及字符串和字符串与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;
}
}
发布于 2019-06-06 05:53:31
只需执行以下操作:
void Update()
{
scoreText.text = (score < 100) ? score.ToString() : "You Win";
}
https://stackoverflow.com/questions/56468317
复制相似问题