Ejemplo n.º 1
0
    void Start()
    {
        EnemyNotInsideList = false;
        TempEnemy          = null;

        foreach (GameObject playerGO in GameObject.FindGameObjectsWithTag("Player"))
        {
            if (playerGO.layer == 9)
            {
                HealthBarAboveEnemy temp = new HealthBarAboveEnemy();
                temp.PlayerHealthScript = playerGO.GetComponent <Health>();

                temp.HealthBarAbovePlayer = Instantiate(HealthBar);

                temp.HealthBarAbovePlayer.transform.GetChild(1).GetComponent <Text>().text = playerGO.GetComponent <Player>().username;
                //GameObject.Find("PlayerUI").transform
                temp.HealthBarAbovePlayer.transform.SetParent(MainPlayer.GetComponent <PlayerSetup>().GetPlayerUI().transform);
                HealthBarEnemyList.Add(temp);
            }
            else if (playerGO.layer == 8)// Main Player
            {
                MainPlayer = playerGO;
                camera     = MainPlayer.GetComponentInChildren <Camera>();
            }
        }
        amtOfPlayers = HealthBarEnemyList.Count;
    }
Ejemplo n.º 2
0
    void CheckEnemyList()
    {
        //bool EnemyNotInsideList = false;
        //GameObject TempEnemy=null;

        if (amtOfPlayers == 0)
        {
            Debug.Log("AmtPlayers==0");
            foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player"))
            {
                if (player.layer == 9)
                {
                    HealthBarAboveEnemy temp = new HealthBarAboveEnemy();
                    temp.PlayerHealthScript   = player.GetComponent <Health>();
                    temp.HealthBarAbovePlayer = Instantiate(HealthBar);
                    if (player.GetComponent <Player>().username != MainPlayer.GetComponent <Player>().username)
                    {
                        temp.HealthBarAbovePlayer.transform.GetChild(1).GetComponent <Text>().text = player.GetComponent <Player>().username;
                        Debug.Log(player.GetComponent <Player>().username);
                        temp.HealthBarAbovePlayer.transform.SetParent(MainPlayer.GetComponent <PlayerSetup>().GetPlayerUI().transform);
                        HealthBarEnemyList.Add(temp);
                    }
                }
                else if (player.layer == 8)// Main Player
                {
                    MainPlayer = player;
                    camera     = MainPlayer.GetComponentInChildren <Camera>();
                }
            }
            amtOfPlayers = HealthBarEnemyList.Count;
        }
        else
        {
            foreach (GameObject playerGO in GameObject.FindGameObjectsWithTag("Player"))
            {
                foreach (HealthBarAboveEnemy temp in HealthBarEnemyList)
                {
                    if (playerGO.layer == 9)
                    {
                        if (temp.PlayerHealthScript.gameObject.name == playerGO.name) // Check whether player is not the same
                        {
                            EnemyNotInsideList = false;
                            TempEnemy          = null;
                            break;
                        }
                        else
                        {
                            EnemyNotInsideList = true;
                            TempEnemy          = playerGO;
                        }
                    }

                    if (EnemyNotInsideList)
                    {
                        Debug.Log("YES");
                        HealthBarAboveEnemy TempHealthBar = new HealthBarAboveEnemy();
                        TempHealthBar.PlayerHealthScript   = TempEnemy.GetComponent <Health>();
                        TempHealthBar.HealthBarAbovePlayer = Instantiate(HealthBar);
                        TempHealthBar.HealthBarAbovePlayer.transform.GetChild(1).GetComponent <Text>().text = TempEnemy.GetComponent <Player>().username;
                        Debug.Log(TempEnemy.GetComponent <Player>().username);
                        TempHealthBar.HealthBarAbovePlayer.transform.SetParent(MainPlayer.GetComponent <PlayerSetup>().GetPlayerUI().transform);
                        HealthBarEnemyList.Add(TempHealthBar);
                        amtOfPlayers = HealthBarEnemyList.Count;
                    }
                }
            }
        }
    }