FormatException: Input string was not in a correct format.
System.Number.ThrowOverflowOrFormatException (System.Boolean overflow, System.String overflowResourceKey) (at <834b2ded5dad441e8c7a4287897d63c7>:0)
System.Number.ParseInt32 (System.ReadOnlySpan`1[T] value, System.Globalization.NumberStyles styles, System.Globalization.NumberFormatInfo info) (at <834b2ded5dad441e8c7a4287897d63c7>:0)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameContoller : MonoBehaviour
{
[SerializeField]
private Sprite bgImage;
public Sprite[] puzzles;
public List<Sprite> gamePuzzles = new List<Sprite>();
public List btns = new List();
private bool firstGuess, secondGuess;
private int countGuesses;
private int countCorrectGuesses;
private int gameGuesses;
private int firstGuessIndex, secondGuessIndex;
private string firstGuessPuzzle, secondGuessPuzzle;
void Awake(){
puzzles = Resources.LoadAll (“Sprites/Fruits”);
}
void Start() {
GetButtons ();
AddListener ();
AddGamePuzzles();
gameGuesses = gamePuzzles.Count / 2;
}
void GetButtons(){
GameObject objects = GameObject.FindGameObjectsWithTag (“PuzzleButton”);
for(int i = 0; i < objects.Length; i++){
btns.Add(objects[i].GetComponent<Button>());
btns[i].image.sprite = bgImage;
}
}
void AddGamePuzzles(){
int looper = btns.Count;
int index = 0;
for (int i = 0; i < looper; i++){
if(index == looper / 2){
index = 0;
}
gamePuzzles.Add(puzzles[index]);
index++;
}
}
void AddListener(){
foreach (Button btn in btns){
btn.onClick.AddListener( ()=> PickAPuzzle());
}
}
public void PickAPuzzle(){
if (!firstGuess){
firstGuess = true;
firstGuessIndex = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);
firstGuessPuzzle = gamePuzzles[firstGuessIndex].name;
btns[firstGuessIndex].image.sprite = gamePuzzles[firstGuessIndex];
}else if (!secondGuess){
secondGuess = true;
secondGuessIndex = int.Parse(UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name);
secondGuessPuzzle = gamePuzzles[secondGuessIndex].name;
btns[secondGuessIndex].image.sprite = gamePuzzles[secondGuessIndex];
countGuesses++;
StartCoroutine(CheckIfThePuzzleMatch());
}
}
IEnumerator CheckIfThePuzzleMatch(){
yield return new WaitForSeconds (1f);
if (firstGuessPuzzle == secondGuessPuzzle){
yield return new WaitForSeconds (.5f);
btns[firstGuessIndex].interactable = false;
btns[secondGuessIndex].interactable = false;
btns[firstGuessIndex].image.color = new Color(0, 0, 0, 0);
btns[secondGuessIndex].image.color = new Color(0, 0, 0, 0);
CheckIfTheGameIsFinished();
}else {
yield return new WaitForSeconds (.5f);
btns[firstGuessIndex].image.sprite = bgImage;
btns[secondGuessIndex].image.sprite = bgImage;
}
yield return new WaitForSeconds (.5f);
firstGuess = secondGuess = false;
}
void CheckIfTheGameIsFinished() {
countCorrectGuesses++;
if(countCorrectGuesses == gameGuesses){
Debug.Log("Game Finised");
Debug.Log("It took you"+ countGuesses + "many guess(es) to finish the game");
}
}
}