Im trying to make some card game, and i found some good start at unity asnwers so i used it. Now i have problem. When i start game it should wait for player to click on deal button(Podijeli) to deal cards. But it doesnt, it just continuously keep doing that like a player is clicking all time on that button from start. I dont know why it is happening since, it is not in Update() function. I figured out that when i comment calling functions in OnGUI resolve problem. If i comment deal button it stops dealing cards but then of course i dont have button to deal.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SpilKarata : MonoBehaviour {
public List<GameObject> spil = new List<GameObject>();
public List<GameObject> karte = new List<GameObject>();
public List<GameObject> ruka = new List<GameObject>();
public int brojpodijeljenihkrata = 0;
public bool resetDugme = false;
void ResetujSpil()
{
brojpodijeljenihkrata = 0;
for (int i = 0; i < ruka.Count; i++)
{
Destroy(ruka[i]);
}
ruka.Clear();
karte.Clear();
karte.AddRange(spil);
resetDugme = false;
}
GameObject PodjeliKarte()
{
if (karte.Count == 0)
{
resetDugme = true;
return null;
}
int karta = Random.Range(0, karte.Count - 1);
GameObject go = GameObject.Instantiate(karte[karta]) as GameObject;
karte.RemoveAt(karta);
return go;
}
// Use this for initialization
void Start()
{
ResetujSpil();
}
void GotovaIgra()
{
ResetujSpil();
}
void KontrolisiPodjeljenuKartu()
{
GameObject novaKarta = PodjeliKarte();
if (novaKarta == null)
{
Debug.Log("Nema Vise Karata!");
resetDugme = true;
return;
}
novaKarta.transform.position = new Vector3((float)brojpodijeljenihkrata / 4, (float)brojpodijeljenihkrata / 4, (float)brojpodijeljenihkrata / 4);
ruka.Add(novaKarta); // dodao sam kartu u ruku
brojpodijeljenihkrata++;
}
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 100, 20), "Podjeli")) ;
{
KontrolisiPodjeljenuKartu();
}
if (GUI.Button(new Rect(150, 10, 100, 20), "Reset")) ;
{
//ResetujSpil();
}
}
}