/* Update stats on screen, used after any modification of stats */ private void UpdateUI(UIUpdate UIUpdate) { switch (UIUpdate) { case UIUpdate.Health: _HUDHealthValue.text = _currentHealth + " / " + _maxHealth + " " + Lang.GetString("ui.stat.health"); _HUDHealth.color = new Color(1 - ((float)_currentHealth / _maxHealth), ((float)_currentHealth / _maxHealth), 0); break; case UIUpdate.Energy: _HUDEnergyValue.text = _currentEnergy + " / " + _maxEnergy + " " + Lang.GetString("ui.stat.energy"); _HUDEnergy.color = new Color(1 - ((float)_currentEnergy / _maxEnergy), ((float)_currentEnergy / _maxEnergy), 0); break; case UIUpdate.Hunger: _HUDHungerValue.text = _currentHunger + " / " + _maxHunger + " " + Lang.GetString("ui.stat.hunger"); _HUDHunger.color = new Color(1 - ((float)_currentHunger / _maxHunger), ((float)_currentHunger / _maxHunger), 0); break; case UIUpdate.Thirst: _HUDThirstValue.text = _currentThirst + " / " + _maxThirst + " " + Lang.GetString("ui.stat.thirst"); _HUDThirst.color = new Color(1 - ((float)_currentThirst / _maxThirst), ((float)_currentThirst / _maxThirst), 0); break; } }
public Color c; // 这个是用来记录坦克的颜色,因为要同步到各个客户端。 public void Start() { this.tank_Number = ++PublicProperty.Tank_Count; if (this.isLocalPlayer == false) { return; } // 赋值uiupdate,并且将uiupdate的tankinformation的属性=这个类身上的对象的tankinformation组件。 this.uiUpdate = GameObject.Find("Canvas").transform.Find("TankInfo").GetComponent <UIUpdate>(); //this.uiUpdate.gameObject.SetActive(true); this.uiUpdate.tankInformation = this; // 获取名字。 // 让坦克的显示名字的3dtext赋值。 this.transform.Find("New Text").GetComponent <TextMesh>().text = GameObject.Find("ControlUI").GetComponent <ControlUI>().tankName; //GameObject.Find("ControlUI").GetComponent<ControlUI>().self = this; //GameObject.Find("ControlUI").GetComponent<ControlUI>().GengXinName(); // 寻Update_Ranking组件,并将其tank_self赋值。 this.update_Ranking = GameObject.Find("Canvas").transform.Find("Ranking").GetComponent <Update_Ranking>(); this.update_Ranking.tank_Self = this; CmdSetTankName(GameObject.Find("ControlUI").GetComponent <ControlUI>().tankName); //this.grade = 1; this.subtitle = GameObject.Find("Canvas").transform.Find("Subtitle").GetComponent <Subtitle>(); this.update_Ranking.Update_UI(); this.uiUpdate.UpdateUI(); // 下面是随机生成坦克的颜色。 this.c = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); //Debug.Log(c); this.transform.Find("TankRenderers/TankChassis").GetComponent <MeshRenderer>().material.color = this.c; this.transform.Find("TankRenderers/TankTracksLeft").GetComponent <MeshRenderer>().material.color = this.c; this.transform.Find("TankRenderers/TankTracksRight").GetComponent <MeshRenderer>().material.color = this.c; this.transform.Find("TankRenderers/TankTurret").GetComponent <MeshRenderer>().material.color = this.c; CmdTankColor(this.c.r, this.c.g, this.c.b); // 先向服务器发送自身坦克的颜色,然后在从服务器端调用相应的函数来改变客户端的颜色。 // 当没加入一辆坦克,就要从服务器端遍历所有的坦克,然后更新其颜色的显示,否则之前加入的坦克颜色该不一样了。 // 下面是将AudioListener激活。 this.GetComponent <AudioListener>().enabled = true; }
private void OnDisable() { update = null; lightLevel = MAX_LT; hp = MAX_HP; }
private void Start() { instance = this; update += UpdateUI; UpdateUI(); }