Esempio n. 1
0
        /// <summary>
        /// Creates a new playerObject and fully initiates it, spawns it on an open spawn field, returns the object
        /// </summary>
        /// <param name="player"></param>
        public PlayerController SpawnPlayer_Single(PhotonPlayer player)
        {
            PlayerController newPlayerObject = null;

            // new object creation
            if (PlayerObject_Exists(player) == false)
            {
                // allow the CLIENT to create its own player
                if (player.isLocal)
                {
                    GameObject newObject = PhotonNetwork.Instantiate(PlayerObjectPrefab.name, Vector3.zero, Quaternion.identity, 0);
                    newPlayerObject = newObject.GetComponent <PlayerController>();
                    newPlayerObject.Photonplayer = player;               // important!
                    newPlayerObject.transform.SetParent(this.transform);
                    AssignPlayerObjectToPlayer(newPlayerObject, player); // VERY important!
                }
                else
                {
                    return(null); // Exit, because I don't own this player
                }
            }
            else
            {
                newPlayerObject = GetPlayerObject(player);
            }


            // object initialisation & position
            //Position
            int     playerSlotIndex = GetPlayerSlot(player);
            Vector3 spawnPosition   = PlayerSpawns.GetInstance().SpawnList[playerSlotIndex].position;

            newPlayerObject.transform.position = spawnPosition;


            //DEBUG:
            newPlayerObject.GetComponentInChildren <Renderer>().material.color = m_SlotColorList[GetPlayerSlot(player)];

            return(newPlayerObject);
        }