c# - 同时更改列表中游戏对象的颜色
问题描述
所以我有一个完整的游戏对象列表。我想同时改变它们的颜色。我现在这样做的方式是使用 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);
}
}
解决方案
只需交换 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);
}
推荐阅读
- python - 如何沿轴在中点分割数组?(实验室色彩空间离散化)
- algorithm - 给定长度的表达式数量
- c# - 整数数组 - 当前上下文中不存在
- wordpress - 为什么与 nextjs 视图源不对齐,就像在 wordpress 中一样
- listview - Xamarin Forms 列表视图设计
- python - Python 抓取返回无
- python - 在python中用条件替换字符串
- python - 为什么只有 3 个参数时,python 说有 4 个参数?
- php - PHP在子方法中覆盖父返回类型
- powershell - sqldataadapter 在 powershell 中不起作用