PlayerSelector.cs (2690B)
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEngine; 4 using UnityEngine.UI; 5 6 public class PlayerSelector : MonoBehaviour { 7 8 public GameObject button; 9 public GameObject Stats; 10 public Text[] playerTexts; 11 public GameObject[] playerObjects; 12 public ListSelector[] playerHats; 13 14 public List<int> addedControllers; 15 private int playerIn = 0; 16 private string[] controllers = {"Keyboard", "Joystick 1", "Joystick 2", "Joystick 3", "Joystick 4"}; 17 private bool[] controllerIn = {false, false, false, false, false}; 18 19 20 private List<string> playControllers; 21 22 // Update is called once per frame 23 void Update () { 24 if(playerIn >= 1) 25 { 26 button.SetActive(true); 27 } 28 29 if (Input.GetButtonDown("Submit") && !controllerIn[0]) 30 { 31 Debug.Log("Keyboard in"); 32 controllerIn[0] = true; 33 addedControllers.Add(0); 34 ShowText("Keyboard In!"); 35 AddPlayer(); 36 AddController(playerIn, 0); 37 PublicStatHandler.GetInstance().amountOfPlayers = playerIn; 38 PublicStatHandler.GetInstance().hats.Add(null); 39 //Debug.Log(PSH.controllers.Count); 40 } 41 42 for (int i = 1; i < 5; i++) 43 { 44 if(Input.GetButtonDown("jSubmit" + i) || Input.GetButtonDown("jStart" + i)) 45 { 46 if (!controllerIn[i]) 47 { 48 Debug.Log(controllers[i] + " in"); 49 controllerIn[i] = true; 50 addedControllers.Add(i); 51 ShowText(controllers[i] + " In!"); 52 AddPlayer(); 53 AddController(playerIn, i); 54 playerHats[playerIn-1].controller = i-1; 55 PublicStatHandler.GetInstance().amountOfPlayers = playerIn; 56 PublicStatHandler.GetInstance().hats.Add(null); 57 //Debug.Log(PSH.controllers.Count); 58 } 59 } 60 } 61 62 } 63 64 private void AddController(int player, int index) 65 { 66 PublicStatHandler.GetInstance().slimes[player - 1].GetComponent<PlayerMovement>().setUpControls(index); 67 } 68 69 private void ShowText(string infoText) 70 { 71 if (playerIn <= 4) 72 { 73 playerTexts[playerIn].gameObject.transform.GetChild(0).GetComponent<Text>().text = infoText; 74 playerTexts[playerIn].gameObject.SetActive(true); 75 playerObjects[playerIn].gameObject.SetActive(true); 76 } 77 } 78 79 private void AddPlayer() 80 { 81 if (playerIn <= 4) 82 { 83 playerIn++; 84 } 85 } 86 public void StartGame() 87 { 88 89 } 90 }