【发布时间】:2016-10-12 10:58:57
【问题描述】:
我的脚本适用于 3D 游戏对象,但不适用于 Text 组件。我怎样才能让它在文本上工作?非常感谢您的帮助。
using UnityEngine;
using System.Collections;
public class Colors : MonoBehaviour
{
public float timer = 0.0f;
Renderer rd;
void Start()
{
rd = gameObject.GetComponent<Renderer>();
}
void Update()
{
timer += Time.deltaTime;
if (timer >= 2.0f)//change the float value here to change how long it takes to switch.
{
// pick a random color
Color newColor = new Color(Random.value, Random.value, Random.value, 1.0f);
// apply it on current object's material
rd.material.color = newColor;
timer = 0;
}
}
}
【问题讨论】:
-
谁支持了这个问题 - 请编辑它,使它真正包含问题(“请帮助”不是一个问题)。
-
您不能以这种方式使用 Update()。只需使用 Invoke 来制作计时器。这很容易。
-
你能给我看看吗?我是编程新手。