slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

WinChecker.cs (4087B)


      1 using System.Collections;
      2 using System.Collections.Generic;
      3 using UnityEngine;
      4 
      5 public class WinChecker : MonoBehaviour {
      6 
      7     // Use this for initialization
      8     private List<GameObject> existingPlayers;
      9     private List<Material> deadBoisMaterials;
     10     private List<Material> deadBoisPMaterials;
     11     private GameObject[] slimePlayers;
     12     public Material deadMat;
     13     public GameObject battleUiObject;
     14     private BattleUiManager battleUiManager;
     15 
     16     private void Awake()
     17     {
     18         Debug.Log("WinScriptStart!!!");
     19 
     20         //battleUiManager = GameObject.Find("Ui").GetComponent<BattleUiManager>();
     21         battleUiManager = battleUiObject.GetComponent<BattleUiManager>();
     22         //GOING TO NEED TO MAKE A SCRIPT THAT JUST FINDS EXISTING PLAYERS ON START SO THIS DOES NOT HAVE TO BE DONE AGAIN AND AGAIN
     23         deadBoisMaterials = new List<Material>();
     24         deadBoisPMaterials = new List<Material>();
     25 
     26         slimePlayers = new GameObject[PublicStatHandler.GetInstance().amountOfPlayers];
     27 
     28         slimePlayers = PublicStatHandler.GetInstance().slimes.ToArray();
     29 
     30         for (int i = 0; i < slimePlayers.Length; i++)
     31         {
     32             GameObject body = slimePlayers[i].transform.GetChild(0).transform.GetChild(2).gameObject;
     33             Debug.Log(deadBoisMaterials.Count);
     34             if (body.GetComponent<Renderer>().sharedMaterial != null)
     35             {
     36                 Debug.Log("Found Material");
     37                 deadBoisMaterials.Add(body.GetComponent<Renderer>().sharedMaterial);
     38             }
     39             if (slimePlayers[i].GetComponentInChildren<ParticleSystem>() != null)
     40             {
     41                 deadBoisPMaterials.Add(slimePlayers[i].transform.GetChild(2).gameObject.GetComponent<Renderer>().sharedMaterial);
     42             }
     43             Debug.Log("Done " + deadBoisMaterials.Count);
     44         }
     45 
     46         for (int i = 0; i < deadBoisMaterials.Count; i++)
     47         {
     48             Debug.Log(deadBoisMaterials[i]); 
     49         }
     50     }
     51 
     52     public void Dead(GameObject deadBoi)
     53     {
     54         SetGhost(deadBoi);
     55         CheckPlayer(deadBoi);
     56     }
     57 
     58 	public void CheckPlayer(GameObject deadBoi)
     59     {
     60         GameObject[] existingPlayersArray = GameObject.FindGameObjectsWithTag("Slime");
     61         existingPlayers = new List<GameObject>();
     62         existingPlayers.AddRange(existingPlayersArray);
     63         existingPlayers.Remove(deadBoi);
     64         if (existingPlayers.Count == 1)
     65         {
     66             deadBoi.GetComponent<PlayerMovement>().slimePercentage = 0;
     67             string returnString = existingPlayers[0].name.Replace("Slime", "P");
     68             battleUiManager.Winner(returnString + " ");
     69         }
     70         Debug.Log(existingPlayers);
     71     }
     72 
     73     public void SetGhost(GameObject deadBoi)
     74     {
     75         deadBoi.tag = "DeadSlime";
     76         deadBoi.layer = 15;
     77         deadBoi.GetComponent<PlayerMovement>().Sword.SetActive(false);
     78         deadBoi.transform.GetChild(1).gameObject.SetActive(false);
     79         GameObject body = deadBoi.transform.GetChild(0).transform.GetChild(2).gameObject;
     80         body.GetComponent<Renderer>().sharedMaterial = deadMat;
     81         deadBoi.transform.GetChild(2).gameObject.GetComponent<Renderer>().sharedMaterial = deadMat;
     82     }
     83 
     84     public void UnSetGhost(GameObject aliveBoi)
     85     {
     86         aliveBoi.tag = "Slime";
     87         aliveBoi.layer = 9;
     88         aliveBoi.GetComponent<PlayerMovement>().isAlive = true;
     89         aliveBoi.GetComponent<PlayerMovement>().Sword.SetActive(true);
     90         aliveBoi.transform.GetChild(1).gameObject.SetActive(true);
     91         int playerNumber = 0;
     92         if(int.TryParse(aliveBoi.name.Replace("Slime", ""), out playerNumber))
     93         {
     94             playerNumber -= 1;
     95         }
     96         
     97         if (deadBoisMaterials.Count - playerNumber < 0)
     98         {
     99             playerNumber = 0;
    100         }
    101         GameObject body = aliveBoi.transform.GetChild(0).transform.GetChild(2).gameObject;
    102         body.GetComponent<Renderer>().sharedMaterial = deadBoisMaterials[playerNumber];
    103         aliveBoi.transform.GetChild(2).gameObject.GetComponent<Renderer>().sharedMaterial = deadBoisPMaterials[playerNumber];
    104 
    105     }
    106 }