public virtual void AddPlayer(long trackID, Vector2 position) { AGameChangerPlayer player = (GameObject.Instantiate(m_playerPrefab, new Vector3(position.x, position.y, 0), Quaternion.identity) as GameObject).GetComponent <AGameChangerPlayer>(); player.TrackID = trackID; m_playerList.Add(player); }
private void AddSpriteToPlayer(AGameChangerPlayer player) { bool spriteSet = false; for (int i = 0; i < m_playerSprites.Count; i++) { int ii = (m_spriteCounter + i) % m_playerSprites.Count; if (m_playerSpriteAvailabilityDict [ii]) { (player as SpaceshipPlayer).m_spaceshipSpriteRenderer.sprite = m_playerSprites [ii]; m_playerSpriteAvailabilityDict [ii] = false; (player as SpaceshipPlayer).SpriteIndex = ii; m_spriteCounter = ii; // Debug.Log("apply sprite " + ii + " to: " + player.gameObject.name); spriteSet = true; break; } } if (!spriteSet) { int iii = Random.Range(0, m_playerSprites.Count); (player as SpaceshipPlayer).m_spaceshipSpriteRenderer.sprite = m_playerSprites [iii]; (player as SpaceshipPlayer).SpriteIndex = iii; m_spriteCounter = iii; // Debug.Log("apply sprite " + iii + " to: " + player.gameObject.name); spriteSet = true; return; } }
public override void AddPlayer(long sessionID, Vector2 position) { AGameChangerPlayer player = (GameObject.Instantiate(m_playerPrefab, new Vector3(position.x, position.y, 0), Quaternion.identity) as GameObject).GetComponent <AGameChangerPlayer>(); player.gameObject.name = string.Format("player_{0}", ++m_playerNum); player.TrackID = sessionID; m_playerList.Add(player); InvaderManager.Instance.PlayerCountChange(m_playerList.Count); AddSpriteToPlayer(player); }