This “should” be easy, but I have been at it all day long. Can anyone PLEASE help me?
I am trying to create two random numbers, display them on the page, and turn one red when there is a match. I must be doing something very wrong, because I can not get the page to display a match. (See this image??)
The layout is has two text ojbects called TextBox1 and TextBox2, each has the “gm.cs” linked to it. There is one button on the page which calls the three functions(getText1, getText2, and clickStart) onClick. It could be something very simple, or I could be doing this all wrong. Any help would be greatly appreciated.
Here is the code for gm.cs
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class gm : MonoBehaviour {
public int text1;
public int text2;
public Text txt1;
public Text txt2;
public void getText1 () {
text1 = Random.Range (0, 9);
Debug.Log (text1);
txt1 = GetComponent<Text> ();
txt1.text = (text1.ToString ("0"));
}
public void getText2 () {
text2 = Random.Range (0, 9);
Debug.Log (text2);
txt2 = GetComponent<Text>();
txt2.text = (text2.ToString("0"));
}
public void clickStart() {
if (text1 == text2) {
txt1.color = Color.red;
Debug.Log ("We have a match!");
} else {
Debug.Log ("nuthin");
}
}
}