Not able to store the script from Prefab to a List
Options
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; using Photon; using UnityEngine.UI; public class GamePlayManager : Photon.PunBehaviour { public Transform namePanel; public Transform lobbyPanel; public Transform HUD; public InputField editName; public InputField editRoomName; public Text messages; public Text loggedInUser; public Text myRoom; private List<RoomJoiner> rooms = new List<RoomJoiner>(); private string roomName = "DEFAULT ROOM NAME"; private PhotonView gpmPhotonView; private PhotonView myPhotonView; public static List<int> playerIDs = new List<int>(); public static List<Player> playerList1 = new List<Player>(); public static List<string> commCards; static int indexOfShuffledDeck; static List<List<string>> twoCardLists; PhotonPlayer pp; //only populated if get to showdown. Used to add points and win to winner(s) static List<Player> winningPlayers; public void Lobby() { PhotonNetwork.playerName = editName.text; PhotonNetwork.ConnectUsingSettings("v1.0"); messages.text = "Connecting..."; loggedInUser.text = PhotonNetwork.playerName; } public override void OnConnectedToMaster() { PhotonNetwork.JoinLobby (); messages.text = "Entering lobby..."; } public override void OnJoinedLobby() { Debug.Log("Inside the Lobby"); namePanel.gameObject.SetActive (false); messages.gameObject.SetActive(false); lobbyPanel.gameObject.SetActive (true); //PhotonNetwork.JoinRandomRoom (); } public void CreateGame () { roomName = editRoomName.text; if (roomName != "") { RoomOptions roomOptions = new RoomOptions () {IsVisible = true, MaxPlayers = 5}; PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default); lobbyPanel.gameObject.SetActive (false); } } public override void OnPhotonCreateRoomFailed(object[] codeMessage) { if((short) codeMessage [0] == ErrorCode.GameIdAlreadyExists) { PhotonNetwork.room.Name += "-2"; CreateGame (); } } private bool checkSameNameOnPlayersList(string name) { foreach (PhotonPlayer pp in PhotonNetwork.otherPlayers) { if (pp.NickName.Equals(name)) { return true; } } return false; } public override void OnCreatedRoom () { Debug.Log ("Room Created"); messages.gameObject.SetActive(false); } public override void OnReceivedRoomListUpdate () { foreach (RoomJoiner roomBtn in rooms) { Destroy(roomBtn.gameObject); } rooms.Clear (); float i = -120f; foreach (RoomInfo room in PhotonNetwork.GetRoomList()) { if (!room.IsOpen) continue; GameObject buttonPrefab = Resources.Load<GameObject>("JoinRoomBtn"); GameObject roomButton = Instantiate<GameObject>(buttonPrefab); roomButton.GetComponent<RoomJoiner>().RoomName = room.name; string info = room.Name.Trim() + " (" + room.PlayerCount + "/" + room.MaxPlayers + ")"; myRoom.text = info; rooms.Add(roomButton.GetComponent<RoomJoiner>()); roomButton.transform.SetParent (lobbyPanel, false); i += -50f; } } public override void OnJoinedRoom() { Debug.Log ("Room Joined"); if (checkSameNameOnPlayersList (PhotonNetwork.playerName)) { string newName = PhotonNetwork.playerName; do { newName += "-2"; }while (checkSameNameOnPlayersList (newName)); PhotonNetwork.playerName = newName; } lobbyPanel.gameObject.SetActive (false); HUD.gameObject.SetActive (true); Debug.Log ("Local Player Joined the Room"); Debug.Log ("Number of Players in Room "+ PhotonNetwork.playerList.Length); if (PhotonNetwork.playerList.Length > 1) { Debug.Log ("2"); Text otherPlayerText = GameObject.Find ("OtherPlayerNumber").GetComponent<Text> (); otherPlayerText.text = "Other player already in room with ID: "+PhotonNetwork.playerList[0].ID; Player firstPlayer = GameObject.Find ("Player").GetComponent<Player> (); firstPlayer.ID = 1; Debug.Log ("Testing1122111"); //playerList.Add (firstPlayer); StartGame (); } Debug.Log ("Testing11111"); print ("player with ID "+PhotonNetwork.player.ID+" joined room"); Text myPlayerText = GameObject.Find ("MyPlayerNumber").GetComponent<Text> (); myPlayerText.text = "player with ID " + PhotonNetwork.player.ID + " joined room"; //TODO: HOW DO I USE PHOTON PLAYERS WITH MY OWN PLAYER PROPERTIES??? //for now I am creating a list of Players (script type) with the same IDs as photonPlayers print("Number of Photon Players: "+ PhotonNetwork.playerList.Length); //instantiate the player object that just joined (this player needs to have an associated ID) GameObject playerGO = PhotonNetwork.Instantiate("Player", Vector3.zero, Quaternion.identity, 0); Player playerScript = playerGO.GetComponent<Player> (); Debug.Log ("Testing"); // myPhotonView = playerScript.GetComponent<PhotonView> (); playerScript.ID = PhotonNetwork.player.ID; //adding this player to static list GamePlayManager.playerList //TODO: SYNC THIS LIST ACROSS THE NETWORK playerList1.Add (playerScript); if (PhotonNetwork.playerList.Length > 1) { StartGame (); } } //connect void Start () { gpmPhotonView = this.GetComponent<PhotonView> (); Debug.Log ("Game Started"); GameObject.Find("BetSlider").SetActive(false); GameObject.Find ("SliderValText").GetComponent<Text> ().text = ""; GameObject.Find ("ConfirmBetButton").SetActive (false); } void OnGUI() { GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString()); } public override void OnPhotonPlayerConnected(PhotonPlayer photonPlayer) { pp = photonPlayer; Debug.Log ("OnPhotonPlayerConnected: " + photonPlayer); print("new player ID: "+photonPlayer.ID); Text otherPlayerText = GameObject.Find ("OtherPlayerNumber").GetComponent<Text> (); otherPlayerText.text = "new player ID: "+photonPlayer.ID; playerIDs.Add (photonPlayer.ID); } bool gameStarted = false; void Update() { //add the non-local player to playerList when he joins while (PhotonNetwork.playerList.Length < 2) { Debug.Log ("Update Count of Players "+playerList1.Count); Debug.Log ("1"); Player otherPlayer = GameObject.Find ("Player").GetComponent<Player> (); otherPlayer.ID = pp.ID; playerList1.Add (otherPlayer); } if (PhotonNetwork.room.PlayerCount > 1 && gameStarted == false) { gameStarted = true; StartGame (); } } public static void StartGame () { Debug.Log ("GAME STARTED NOW"); print ("number of players in playerList is " + playerList1.Count); GameState.shuffledDeck = ShuffleDeck(); GameState.currentRound = GameState.Rounds.isPreDeal; Debug.Log ("111"); //TODO: INCREMENT DEALER SINCE LAST GAME GameState.dealer = playerList1 [0]; Debug.Log ("222"); GameState.OnGameStarted (); Debug.Log ("abc"); //small blind GameState.smallBlindPlayer.myBetAmount = GameState.smallBlindAmount; GameState.smallBlindPlayer.myChipAmount -= GameState.smallBlindPlayer.myBetAmount; //big blind GameState.bigBlindPlayer.myBetAmount = GameState.bigBlindAmount; GameState.bigBlindPlayer.myChipAmount -= GameState.bigBlindPlayer.myBetAmount; GameState.currentPlayer = GameState.straddlePlayer; Debug.Log ("def"); GenerateTwoCardHands (); GenerateCommCards (); GeneratePlayerHands (); AddPointsToWinners (); } }My script does not store the reference of the script that is attached on a player prefab in a list. When I debug playerList1.count it returns 0.
0