1
我目前正在研究一个具有精灵效果的游戏。玩家有能力在一段时间内改变他们的“冰刀”。 2秒后,我希望效果恢复到正常的“冰刀”。因此,我需要Unity中的一个定时器。我尝试了相当一段时间,不能完成这项工作。计时器不会改变精灵
这里是我的示例代码:
if (other.gameObject.CompareTag("IcePickup"))
{
Destroy(other.gameObject);
timer -= Time.deltaTime;
timer ++;
Blade1 = GameObject.Find("Blade1");
Blade1.gameObject.GetComponent<SpriteRenderer>().sprite = IceBlade;
if (Blade1.gameObject.GetComponent<SpriteRenderer>().sprite = IceBlade)
{
//i put a timer here but i cant figure out why is isnt working and print isnt showing.
if (timer > 2)
{
Blade1.gameObject.GetComponent<SpriteRenderer>().sprite = BladeNormal;
print("working");
}
}
}
OK揭掉,但计时器仍然不起作用 –