void OnGUI() { if (message_shown) { float w = Screen.width, h = Screen.height; GUI.skin = Skin; PlayerDatasScript datas = (PlayerDatasScript)NetworkConnectionInitScript.myPlayer.GetComponent <PlayerDatasScript>(); GUI.Box(new Rect(w * 0.33f, h * 0.25f, w * 0.33f, h * 0.25f), "You have not enough red balls to create a sbire (" + datas.RedBalls.ToString() + " / 5) ! "); } }
void SynchronizePlayerDatas(string datas) { if (Network.peerType == NetworkPeerType.Client) { PlayerDatasScript otherDatas = GameObject.Find("PlayerTmp(Clone)").GetComponent <PlayerDatasScript>(); string[] t_data = datas.Split(new char[] { ';' }); otherDatas.PlayerName = t_data[0]; otherDatas.MaxHealth = float.Parse(t_data[1]); otherDatas.Health = float.Parse(t_data[2]); otherDatas.RedBalls = int.Parse(t_data[3]); otherDatas.YellowBalls = int.Parse(t_data[4]); otherDatas.GreenBalls = int.Parse(t_data[5]); otherDatas.NbCollectedFragments = int.Parse(t_data[6]); } }
void OnMouseDown() { if (IsAtGoodDistance) { PlayerDatasScript datas = (PlayerDatasScript)NetworkConnectionInitScript.myPlayer.GetComponent <PlayerDatasScript>(); if (datas.RedBalls >= 5) { Network.Instantiate(MinionPrefab, minionSpawn.transform.position, minionSpawn.transform.rotation, 0); datas.RedBalls -= 5; } else { message_shown = true; Invoke("CancelShowMessage", MessageTimeOut); } } }
void OnEndOfParty(bool win) { PlayerDatasScript script = PlayerPrefab.GetComponent <PlayerDatasScript>(); if (win) { VictoryMessage = script.PlayerName + ", you win ! "; Audio.PlayOneShot(AudioWin); } else { VictoryMessage = script.PlayerName + ", you loose ... "; Audio.PlayOneShot(AudioLoose); } ShowMessage = true; PlayingState = false; Invoke("End", 5.0f); }
void Update() { if (networkView.isMine && PlayingState) { PlayerDatasScript playerDataScript = PlayerPrefab.GetComponent <PlayerDatasScript>(); PlayerDatasScript otherPlayerDataScript = GameObject.Find("PlayerTmp(Clone)").GetComponent <PlayerDatasScript>(); // Client if (playerDataScript.Health <= 0 || playerDataScript.NbCollectedFragments >= 5) { if (playerDataScript.Health <= 0) { OnEndOfParty(false); } if (playerDataScript.NbCollectedFragments >= 5) { OnEndOfParty(true); } } // Other Client if (otherPlayerDataScript.Health <= 0 || otherPlayerDataScript.NbCollectedFragments >= 5) { if (otherPlayerDataScript.Health <= 0) { OnEndOfParty(true); } if (otherPlayerDataScript.NbCollectedFragments >= 5) { OnEndOfParty(false); } } } }