Hi, I’m very new to C# and am stuck trying to change the color of multiple gameobjects in syncronization.
Basically I have up to 20 lasers on the screen at any given moment which when effected by a buff they change color. When the buff duration is running low, I want all lasers in the scene to flicker back and forth from thier original color. I have tried 2 methods of doing so but both result in the lasers changing color individually instead of all in sync.
Here’s the snippets of the code performing the color change. Any help would be greatly appreciated.
attempt 1:
void Update ()
{
if ((player.laserFlash) && (player.laserOddEven))
{
if (player.speedBoostStage == 1)
{
spriteRenderer.color = speedStage2Color;
}
if (player.speedBoostStage == 2)
{
spriteRenderer.color = speedStage3Color;
}
}
if ((player.laserFlash) && (!player.laserOddEven))
{
spriteRenderer.color = speedStage1Color;
}
}
Attempt 2 (same as above, but modified the action):
GameObject[] lasers = GameObject.FindGameObjectsWithTag("FriendlyProjectile");
foreach (var go in lasers)
{
spriteRenderer.color = speedStage1Color;
}