【问题标题】:Changing color of Game Objects in a list at the same time同时更改列表中游戏对象的颜色
【发布时间】:2021-01-18 23:29:04
【问题描述】:

所以我有一个完整的游戏对象列表。我想同时改变它们的颜色。我现在的做法是使用 2 个 for 循环逐个更改每个游戏对象的颜色,但我需要同时更新它。这是我的代码

        yield return new WaitForSeconds(2.3f);
        var places = GameObject.FindGameObjectsWithTag("ground");
            for (int i = 0; i <= GOlist.Count; i++)
            {
                renderer = GOlist[i].GetComponent<SpriteRenderer>();
                Color c = renderer.material.color;
                for (float s = 0.28f; s <= 1f; s += 0.02f)
                {
                    c.r = s;
                    c.g = s;
                    c.b = s;

                  renderer.color = c;


                yield return new WaitForSeconds(0.01f);
                }
            }

【问题讨论】:

  • 好吧,不要让它在循环中等待。因为它将在每个之间等待

标签: c# list unity3d colors


【解决方案1】:

只需交换 for 循环...

var places = GameObject.FindGameObjectsWithTag("ground");
for (float s = 0.28f; s <= 1f; s += 0.02f)
{
    for (int i = 0; i <= GOlist.Count; i++)
    {
        renderer = GOlist[i].GetComponent<SpriteRenderer>();
        Color c = renderer.material.color;
        c.r = s;
        c.g = s;
        c.b = s;
        renderer.color = c;
    }
    yield return new WaitForSeconds(0.01f);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-24
    • 1970-01-01
    • 1970-01-01
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    相关资源
    最近更新 更多