So I have a number generator 1-9 and I am using it to pick between 9 random buttons. I have the buttons lighting up certain colors when they are selected, but now I want to make it so when I click it, it highlights with the color. How would I go about doing that? I will link my script below. I tried using parameters but I am getting so confused. Please help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class RandomCircle : MonoBehaviour {
public Image Left;
public Image Center;
public Image Right;
public Image LeftTwo;
public Image CenterTwo;
public Image RightTwo;
public Image LeftThree;
public Image CenterThree;
public Image RightThree;
public Text Score;
private int score = 0;
private float buttonTimer = 1f;
int randomNumber = 0;
// Use this for initialization
void Start () {
RandomCircles ();
}
public void OnButtonClick(int buttonNumber){
Debug.Log (randomNumber);
if (buttonNumber == randomNumber) {
addToScore ();
buttonTime ();
TimerCountdown ();
Score.text = score.ToString ();
Debug.Log ("Right");
} else {
SceneManager.LoadScene ("GameOverScreen");
Debug.Log ("Wrong");
}
System.Threading.Thread.Sleep (1000);
RandomCircles ();
}
void addList(){
}
void addToScore(){
score = score + 1;
}
void buttonTime(){
buttonTimer = 1f;
}
public void clickButtonColor(int image){
Debug.Log ("Here");
image = randomNumber;
Left.GetComponent<Image> ().color = new Color32 (157, 240, 136, 255);
}
void RandomCircles(){
randomNumber = Random.Range(1,1);
switch (randomNumber) {
case 1:
Debug.Log ("One");
Left.GetComponent<Image> ().color = new Color32 (157, 240, 136, 255);
break;
case 2:
Debug.Log ("Two");
Center.GetComponent<Image> ().color = new Color32 (240, 136, 136, 255);
break;
case 3:
Debug.Log ("Three");
Right.GetComponent<Image>().color = new Color32(136,240,240,255);
break;
case 4:
Debug.Log ("Four");
LeftTwo.GetComponent<Image>().color = new Color32(191,136,240,255);
break;
case 5:
Debug.Log ("Five");
CenterTwo.GetComponent<Image>().color = new Color32(240,237,136,255);
break;
case 6:
Debug.Log ("Six");
RightTwo.GetComponent<Image>().color = new Color32(136,154,240,255);
break;
case 7:
Debug.Log ("Seven");
LeftThree.GetComponent<Image>().color = new Color32(157,240,136,255);
break;
case 8:
Debug.Log ("Eight");
CenterThree.GetComponent<Image>().color = new Color32(14,208,192,255);
break;
case 9:
Debug.Log ("Nine");
RightThree.GetComponent<Image>().color = new Color32(199,0,255,255);
break;
}
}
// Update is called once per frame
void Update () {
TimerCountdown ();
}
void TimerCountdown(){
buttonTimer -= Time.deltaTime;
if (buttonTimer < 0) {
TimerZero ();
}
}
void TimerZero(){
Left.GetComponent<Image>().color = new Color32 (38,38,38,255);
Center.GetComponent<Image>().color = new Color32 (38,38,38,255);
Right.GetComponent<Image>().color = new Color32 (38,38,38,255);
LeftTwo.GetComponent<Image>().color = new Color32 (38,38,38,255);
CenterTwo.GetComponent<Image>().color = new Color32 (38,38,38,255);
RightTwo.GetComponent<Image>().color = new Color32 (38,38,38,255);
LeftThree.GetComponent<Image>().color = new Color32 (38,38,38,255);
CenterThree.GetComponent<Image>().color = new Color32 (38,38,38,255);
RightThree.GetComponent<Image>().color = new Color32 (38,38,38,255);
}
}
This is the method I was calling to change the buttons color.
public void clickButtonColor(int image){
Debug.Log ("Here");
image = randomNumber;
Left.GetComponent<Image> ().color = new Color32 (157, 240, 136, 255);
}