/// <summary> /// Displays the grid. /// </summary> void OnGUI() { if (_ObjectManager.gameState.displayGrid) { foreach (Node node in nodes) { if (node.isBuildable) { Vector3 posVector = Camera.main.WorldToScreenPoint(node.unityPosition); GUI.DrawTexture(new Rect(posVector.x, Screen.height - posVector.y, nodeSize.x, nodeSize.y), gridTexture); } } } foreach (EnemyBase Gob in _ObjectManager.ThingsWithHealthBars()) { //Health Bar float healthRatio = (((float)Gob.Health) / ((float)Gob.maxHealth)); if (healthRatio != 1) { Vector2 objSize = Gob.GetPixelSize(); float width = Gob.healthBarSize.x; float height = Gob.healthBarSize.y; width = width * healthRatio; Vector3 wantedPos = Camera.main.WorldToScreenPoint(Gob.transform.position); GUI.color = new Color(2 * (1 - healthRatio), 2 * healthRatio, 0); GUI.DrawTexture(new Rect(wantedPos.x - width / 2, Screen.height - wantedPos.y - objSize.y / 2, width, height), healthTexture); } } }
/// <summary> /// Displays the grid. /// </summary> void OnGUI() { foreach (EnemyBase Gob in _ObjectManager.ThingsWithHealthBars()) { //Health Bar float healthRatio = (((float)Gob.Health) / ((float)Gob.maxHealth)); if (healthRatio != 1) { Vector2 objSize = Gob.GetPixelSize(); float width = Gob.healthBarSize.x; float height = Gob.healthBarSize.y; width = width * healthRatio; Vector3 wantedPos = Camera.main.WorldToScreenPoint(Gob.transform.position); GUI.color = new Color(2 * (1 - healthRatio), 2 * healthRatio, 0); GUI.DrawTexture(new Rect(wantedPos.x - width / 2, Screen.height - wantedPos.y - objSize.y / 2, width, height), healthTexture); } } }