So I am trying to declare a color array by using this.
Color[] Colors = {new Color(84, 60, 39), new Color(167, 156, 135), new Color(138, 106, 71), new Color(202, 203, 199), new Color(187, 151, 142), new Color(188, 182, 178)};
It works just fine, there’s no error so I tried using the array to change my Camera Background color by doing this.
Main_Camera.backgroundColor = Colors[index];
The result is that the Main_Camera immediately change it’s color to white. I don’t know why.
This is the complete code if necessary:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ChangingPicture : MonoBehaviour
{
public Button NextButton;
public Button BackButton;
public Image ImageUI;
public TMP_Text Title;
public Camera Main_Camera;
public Sprite[] Pictures;
string[] Pictures_Text = {"Coffee", "Tea", "Thai Tea", "Milk", "Soda", "McFlurry"};
Color[] Colors = {new Color(84, 60, 39), new Color(167, 156, 135), new Color(138, 106, 71), new Color(202, 203, 199), new Color(187, 151, 142), new Color(188, 182, 178)};
int index, LowerLimit = 0, UpperLimit = 5;
// Start is called before the first frame update
void Start()
{
index = 0;
UpdateAll();
NextButton.onClick.AddListener(Forward);
BackButton.onClick.AddListener(Backward);
}
// Update is called once per frame
void Update()
{
//do nothing
}
void Forward() {
if(index >= UpperLimit) {
index = UpperLimit;
} else {
index++;
}
UpdateAll();
}
void Backward() {
if(index == LowerLimit) {
index = LowerLimit;
} else {
index--;
}
UpdateAll();
}
void UpdateAll() {
ImageUI.sprite = Pictures[index];
Title.text = Pictures_Text[index];
Main_Camera.backgroundColor = Colors[index];
Debug.Log(Colors[index]);
}
}