如何统一在 C# 中的给定条件下使 textView 可见?
How to Make a textView visible on a given condition in C# in unity?
我正在学习 unity,我想知道如何使文本视图在给定条件下可见 5 秒,然后再次使其不可见并在该条件满足时继续显示。
if (scoreCount >= COMBO_JEWEL_GAIN)
{
//MaketextVisible for 5 sec;
//MaketextInvisible;
}
假设您已经声明了一个名为 text
的游戏对象,您可以使用 Coroutines
if (scoreCount >= COMBO_JEWEL_GAIN)
{
text.SetActive( true ) ;
StartCoroutine( DelayAction( () =>
{
text.SetActive( false ) ;
}, 5 ) ) ;
}
// ...
// Outside of the function above
private IEnumerator DelayAction( System.Action action, float delay )
{
yield return new WaitForSeconds( delay ) ;
if( action != null )
action() ;
}
我正在学习 unity,我想知道如何使文本视图在给定条件下可见 5 秒,然后再次使其不可见并在该条件满足时继续显示。
if (scoreCount >= COMBO_JEWEL_GAIN)
{
//MaketextVisible for 5 sec;
//MaketextInvisible;
}
假设您已经声明了一个名为 text
的游戏对象,您可以使用 Coroutines
if (scoreCount >= COMBO_JEWEL_GAIN)
{
text.SetActive( true ) ;
StartCoroutine( DelayAction( () =>
{
text.SetActive( false ) ;
}, 5 ) ) ;
}
// ...
// Outside of the function above
private IEnumerator DelayAction( System.Action action, float delay )
{
yield return new WaitForSeconds( delay ) ;
if( action != null )
action() ;
}