
It looks like you're new here. If you want to get involved, click one of these buttons!
Does anyone know how to change background color in game, like for example in an endless runner if you pass 100 meters the background turns blue or something like that?
Answers
using UnityEngine;
using UnityEngine.UI;
public class MyScript : MonoBehaviour
{
public float playerMeter;
public Image background;
public Camera cam;
public Color bgColor, camColor;
void Start()
{
cam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
cam.clearFlags = CameraClearFlags.SolidColor;
}
void Update()
{
//Using UI
if (playerMeter >= 100)
{
background.color = bgColor;
}
//Using Camera
if (playerMeter >= 100)
{
cam.backgroundColor = camColor;
}
}
}
If you want to animate the color from white to something like blue use Dotween or Leantween.