I’m trying to create a system where each player selects a country to play as. You click on the flag of the country you want, then it deletes that country so no other player can choose it. It increases a variable representing which player the system is on, and then it goes to a different scene depending on how many players there are. The problem is that it sets the variable every time to 0, and increases it by one, so the console just puts out 1, 1, 1, 1 when I test it. As such, it never goes to the next scene. Here is the code for the system itself:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class ButtonHandler : MonoBehaviour
{
int currentPlayer = 0;
int players;
private void Start()
{
players = PlayerPrefs.GetInt("Players");
}
public enum Country { Britain, France, Germany, Switzerland };
public Country buttonCountry;
private void Update()
{
}
void OnMouseDown()
{
currentPlayer++;
Debug.Log(currentPlayer);
Destroy(gameObject);
if (currentPlayer >= players)
{
SceneManager.LoadScene(players);
}
}
}
and here is where the PlayerPrefs are defined: `using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Start : MonoBehaviour {
public int players;
public void startGame(int playerCount)
{
players = playerCount;
PlayerPrefs.SetInt("Players", players);
PlayerPrefs.SetInt("Index", 0);
SceneManager.LoadScene(1);
}
}