Question by
Calcio39 · Feb 24, 2016 at 02:44 PM ·
c#camerachange color
Change camera background color (and back) when gameObject button pressed
I am struggling for days with what i thought was a simple feature! I have a a 2d side scrolling game with the camera background Black. I have a gameObject button which when pressed I would like the background to change to white for 3 seconds, then return to black. I am working in c# - if anyone can help that would be awesome
Comment
Best Answer
Answer by Jordi-Bonastre · Feb 24, 2016 at 03:36 PM
You should use a Coroutine. This code works correctly:
IEnumerator WhiteAndBlack(float waitTime) {
_camera.backgroundColor = Color.white;
yield return new WaitForSeconds(waitTime);
_camera.backgroundColor = Color.black;
}
public void ChangeColor()
{
StartCoroutine ( WhiteAndBlack(3f) );
}