如何使用SetActiveRecursively (矩=1秒)在Unity中创建闪烁对象。
我的示例(用于更改):
public GameObject flashing_Label;
private float timer;
void Update()
{
while(true)
{
flashing_Label.SetActiveRecursively(true);
timer = Time.deltaTime;
if(timer > 1)
{
flashing_Label.SetActiveRecursively(false);
timer = 0;
}
}
}发布于 2014-02-05 13:49:28
使用InvokeRepeating
public GameObject flashing_Label;
public float interval;
void Start()
{
InvokeRepeating("FlashLabel", 0, interval);
}
void FlashLabel()
{
if(flashing_Label.activeSelf)
flashing_Label.SetActive(false);
else
flashing_Label.SetActive(true);
}发布于 2014-02-05 13:44:40
查看一下统一WaitForSeconds函数。
通过int param。(秒),您可以切换您的gameObject。
bool fadeIn =真;
IEnumerator Toggler()
{
yield return new WaitForSeconds(1);
fadeIn = !fadeIn;
}然后通过StartCoroutine(Toggler())调用此函数。
发布于 2015-01-11 07:10:37
您可以使用Coroutines和新的United4.6GUI来非常容易地实现这一点。请看这篇文章,这篇文章歪曲了一篇文章。YOu可以很容易地将其修改为游戏对象。
闪烁文字- TGC
如果你只需要密码,给你
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class FlashingTextScript : MonoBehaviour {
Text flashingText;
void Start(){
//get the Text component
flashingText = GetComponent<Text>();
//Call coroutine BlinkText on Start
StartCoroutine(BlinkText());
}
//function to blink the text
public IEnumerator BlinkText(){
//blink it forever. You can set a terminating condition depending upon your requirement
while(true){
//set the Text's text to blank
flashingText.text= "";
//display blank text for 0.5 seconds
yield return new WaitForSeconds(.5f);
//display “I AM FLASHING TEXT” for the next 0.5 seconds
flashingText.text= "I AM FLASHING TEXT!";
yield return new WaitForSeconds(.5f);
}
}
}P.S:尽管它似乎是一个无限循环,通常被认为是一种糟糕的编程实践,但在这种情况下,它工作得很好,因为一旦对象被销毁,MonoBehaviour就会被销毁。此外,如果您不需要它永远闪现,您可以添加一个终止条件,根据您的要求。
https://stackoverflow.com/questions/21578810
复制相似问题