public GameObject pons;
public GameObject frontallobe1;
void Start() {//runs when this gameobject is first added to the game and only runs once.
StartCoroutine("Glow", 2f, pons);
StartCoroutine("Glow", 4f, frontallobe1);
}
//store the last glowing object and color,
//so it can stop glowing.
private GameObject lastGlow;
private Color preGlowColor;
IEnumerator Glow(float waitTime, GameObject go){
yield return new WaitForSeconds(waitTime);
if(lastGlow!=null){//if first time running, ignore this
lastGlow.renderer.material.color=preGlowColor;//set the color back to its original color
}
preGlowColor = go.renderer.material.color;//save the original color
lastGlow = go;//save the now glowing game object, replacing any prior ones
go.renderer.material.color=Color.red;//make gameobject glow - you might even want to make a fancy Color.Lerp here
}
There are many ways to skin this cat. The above way works by 'saving' the last glowing thing (and it's color, if that's important) so that when something new glows, it 'cancels' the old glow by replacing the last object 'glow color' with its original color. But this way will only work if only one thing is glowing at a time (if you want to have two things glowing, the first one will be canceled by the second one).
If the requirement is that 'any number of things can start glowing at the same time', then you will need to make an array (a big list of stuff) of all the things that are currently glowing (and possibly their original colors as well), so that when something new starts to glow that all the old stuff (everything in the list of 'currently glowing' stuff) gets turned off properly.
Also adding a color lerp in there would make it look pretty, instead of just 'popping' on and off.
And lastly, if you didn't notice, I changed the invoke to a start coroutine because I think it made it look a little prettier (or more readable to me). Also I changed the Update function to Start: this means that it is only ran once, rather than once per rendered frame (if it was still in update, it would flicker between the two pieces over and over again, after about 4 seconds).
Hope that helps!
InvokeRepeat
work for you? \$\endgroup\$