i have a small problem i am making calculator and i want to decrease my code lenght by writting for loop, for the number part, i solved problem for infinity loop on ("OnGUI") part, but now it dosen't show my any numbers, can someone explain to me why is that? Thank you.
using UnityEngine;
using System.Collections;
public class Calculator : MonoBehaviour {
int temp,rectX,t,count;
bool endOfCalc;
string val;
private void Start()
{
endOfCalc = false;
val = "";
temp = 0;
t = 9;
count = 0;
/*for(int x = 0; x <= 9; x++)
{
rectX += 20;
Debug.Log (rectX);
if (GUI.Button (new Rect(10,160+rectX,30,20), x.ToString ()))
{
Calculation(x.ToString ());
}
}*/
}
private void OnGUI()
{
val = GUI.TextField (new Rect(10,100,200,20), val);
if (GUI.Button (new Rect(40,120,30,20), "+"))
{
temp += int.Parse (val);
val = "";
}
if (GUI.Button (new Rect(10,120,30,20),"="))
{
temp += int.Parse (val);
val = temp.ToString ();
endOfCalc = true;
}
// The problem is here, i can't see any buttons.
for(int x= 0; x<=t; t--)
{
if (GUI.Button (new Rect(10,140,30,20), count.ToString()))
{
Calculation(count.ToString ());
}
count++;
}
}
void Calculation(string str)
{
if (!endOfCalc)
val += str;
else
val = "";
val += str;
endOfCalc = false;
temp = 0;
}
}