Commit 13072770 by Tim Reiter

started working on game over panel

parent 3c8982aa
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class GameMaster : MonoBehaviour {
DeserializedLevelsLoader levelLoader;
public GameObject gameOverPanel;
public Text rankingText;
// Use this for initialization
void Start () {
......@@ -11,9 +15,26 @@ public class GameMaster : MonoBehaviour {
levelLoader.loadLevel();
}
// Update is called once per frame
void Update () {
public void gameOver(List<string> ranking)
{
gameOverPanel.SetActive(true);
Debug.Log(ranking.Count);
if (ranking.Count > 0)
{
rankingText.text = "1st: " + ranking[0];
}
if (ranking.Count > 1)
{
rankingText.text += "\n2nd: " + ranking[1];
}
if (ranking.Count > 2)
{
rankingText.text += "\n3rd: " + ranking[2];
}
if (ranking.Count > 3)
{
rankingText.text += "\n4th: " + ranking[3];
}
}
}
......@@ -15,6 +15,7 @@ public class GameStateTracker : MonoBehaviour {
private int winnerPlayer;
private List<string> ranking;
private GameMaster gameMaster;
void Awake()
......@@ -24,13 +25,9 @@ public class GameStateTracker : MonoBehaviour {
// Use this for initialization
void Start () {
gameMaster = GetComponent<GameMaster>();
}
// Update is called once per frame
void Update () {
}
public void setNumberOfPlayers(int players)
{
......@@ -52,33 +49,22 @@ public class GameStateTracker : MonoBehaviour {
public void gameOver()
{
Time.timeScale = 0.0f;
Time.timeScale = 0.0f; //stops the game
//find the player who is still alive:
string playerStillAlive = "";
GameObject[] players = GameObject.FindGameObjectsWithTag("Player");
string loser = "";
foreach (GameObject p in players){
foreach (GameObject p in players)
{
if (p.GetComponent<PlayerHealth>().getCurrentHealth() > 0)
{
loser = p.name;
playerStillAlive = p.name;
ranking.Add(playerStillAlive);
break;
}
}
if (string.IsNullOrEmpty(loser))
{
Debug.LogError("No loser found");
loser = "None";
}
else
{
ranking.Add(loser);
}
Debug.Log("Ranking: ");
for (int i = 0; i < ranking.Count; i++)
{
Debug.Log((i+1) + "th: " + ranking[i]);
}
//Ranking enthält an erster stelle den gewinner (der als erster gestorben ist) und dann absteigend die danach als String.
}
gameMaster.gameOver(ranking); //shows the game over screen
}
}
......@@ -13,12 +13,19 @@ public class PlayerHealth : MonoBehaviour {
private GameStateTracker gameStateTracker;
private bool hasShield = false;
void Start()
{
gameStateTracker = GameObject.Find("GameMaster").GetComponent<GameStateTracker>(); //warning: geht kaputt wenn der name "Game Master" sich aendert.
playerControl = gameObject.GetComponent<PlayerControl>();
string healthbarName = "HealthBar" + playerControl.playerNumber.ToString();
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
if (name.EndsWith("(Clone)"))
{
name = name.Split(new char[] { '(' })[0];
}
}
// Update is called once per frame
......
fileFormatVersion: 2
guid: c07127002e5da3d4f8e6c8df3baacab8
folderAsset: yes
timeCreated: 1433459937
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment