- Home /
Retunrn INT valu from Specific button.text
Hi all, it's my firs time with Unity. I have 4 buttons, each one get random int value and print it in the scene. i need to make my buttons work, it should return me the value of the button i click but i not have any idea how to do it.
please help.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Buttons : MonoBehaviour {
public GameObject ui_b1;
public GameObject ui_b2;
public GameObject ui_b3;
public GameObject ui_b4;
Text b1;
Text b2;
Text b3;
Text b4;
public int B1;
public int B2;
public int B3;
public int B4;
void Start () {
int temp = Random.Range (1,5);
b1 = ui_b1.GetComponent<Text>();
b2 = ui_b2.GetComponent<Text>();
b3 = ui_b3.GetComponent<Text>();
b4 = ui_b4.GetComponent<Text>();
B1 = Random.Range (0, 101);
B2 = Random.Range (0, 101);
B3 = Random.Range (0, 101);
B4 = Random.Range (0, 101);
}
void Update () {
b1.text = ""+B1;
b2.text = ""+B2;
b3.text = ""+B3;
b4.text = ""+B4;
}
}
Comment
Your answer

Follow this Question
Related Questions
UI Buttons Stop Working After I Load Another Scene And Then Come Back. 4 Answers
Touch input problem 1 Answer
Buttons stopped working after I temporarily changed the font. 1 Answer
Inventory UI buttons not working 1 Answer
4.6 UI Dynamic button event system PointerEnter, PointerExit, PointerUp etc. 1 Answer