【发布时间】:2021-02-26 09:56:19
【问题描述】:
提前致歉!初学者在这里。我发现自己越来越频繁地使用一个特性,就像我将要描述的那样,存储一个临时变量并调用它。我尝试查找它,但没有找到与我的问题特别相关的答案。
我正在尝试做一些非常简单的事情,一旦我了解它是如何完成的,我就可以将它应用到其他类型(等等)。
假设我想更改灯光的颜色,但将原始灯光设置存储在一个变量中,然后在计时器用完后重新调用该设置。这是针对 Unity 中的游戏。
if (powerupEnabled)
{
CameraShake.instance.shakeDuration = 5;
powerupTimer -= Time.deltaTime;
snakeheadFire.SetActive(true);
//lightIngame.intensity = 0.8f;
Color original_color = lightIngame.color; // <<<< Trying to store original color set in game in variable
lightIngame.color = Color.red;
if (lightIngame != null)
{
// add the amount of time that has passed since last frame
timeElapsed += Time.deltaTime;
// if the amount of time passed is greater than or equal to the delay
if (timeElapsed >= delay)
{
// reset the time elapsed
timeElapsed = 0;
// toggle the light
ToggleLight();
}
}
if (powerupTimer <= 0)
{
lightIngame.color = original_color; // <<<< Trying to restore original color set in game from variable
CameraShake.instance.shakeDuration = 0;
lightIngame.intensity = 1.12f;
print("Timer stopped!");
powerupTimer = 5f;
snakeheadFire.SetActive(false);
powerupEnabled = false;
}
}
所以基本上我尝试了Color original_color = lightIngame.color,但是一旦我调用原始颜色,灯光就不会改变到原来的设置。两条线(颜色变化)用 ' 引用
我错过了什么?
【问题讨论】: