void Awake() { if (s_settings != null) { throw new System.InvalidProgramException("there is more than one game settings object!"); } s_settings = this; }
// Called by ExampleCharacterSelect using GameObject.SendMessage void InitializeFromCharacterSelect(ExampleCharacterSelect.StartInfo startInfo) { Init(); // Save the netplayer object so we can use it send messages to the phone m_netPlayer = startInfo.netPlayer; // Register handler to call if the player disconnects from the game. m_netPlayer.OnDisconnect += Remove; // Handle Namechange. Either use the one passed in or make a new one m_playerNameManager = startInfo.playerNameManager; m_playerNameManager.OnNameChange += ChangeName; // Setup events for the different messages. m_netPlayer.RegisterCmdHandler <MessageMove>("move", OnMove); ExampleCharacterSelectGameSettings settings = ExampleCharacterSelectGameSettings.settings(); m_position = new Vector3(Random.Range(0.0f, settings.areaWidth), 0, Random.Range(0.0f, settings.areaHeight)); transform.localPosition = m_position; SetName(m_playerNameManager.Name); Color color = new Color(Random.value, Random.value, Random.value); // make one random component a minimum brightness color[RandInt(3)] = Random.value * 0.5f + 0.5f; SetColor(color); }
private void PickPosition() { ExampleCharacterSelectGameSettings settings = ExampleCharacterSelectGameSettings.settings(); m_position.x = m_rand.Next(settings.areaWidth); m_position.z = m_rand.Next(settings.areaHeight); gameObject.transform.localPosition = m_position; }
private void OnMove(MessageMove data) { ExampleCharacterSelectGameSettings settings = ExampleCharacterSelectGameSettings.settings(); m_position.x = data.x * settings.areaWidth; m_position.z = settings.areaHeight - (data.y * settings.areaHeight) - 1; // because in 2D down is positive. gameObject.transform.localPosition = m_position; }
void Cleanup() { s_settings = null; }