Example #1
0
    public void Initialize()
    {
        GameObject gTeam = GameObject.FindGameObjectWithTag("Player Team");
        Team team = gTeam.GetComponent<Team>();
        m_myTeam = team.m_teamNumber;

        // Cache the global storage for health data
        GameObject healthValues = GameObject.Find ("Player Values");
        m_healthPool = healthValues.GetComponent<PlayerValues>();

        m_allyPercentages = m_healthPool.GetMyTeamHP(Network.player, out m_myTeam);
        m_enemyPercentages = m_healthPool.GetOppTeamHP(m_myTeam);

        initialized = true;

        /*// Get the PlayerDataManager script so that we can get its data on players
        GameObject playerManager = GameObject.Find("Player Data Manager");
        PlayerDataManager manager = playerManager.GetComponent<PlayerDataManager>();

        // Get the player's team number
        int myTeam = -1;
        myTeam = manager.GetTeam(Network.player);
        Debug.Log("Player has a team: " + (myTeam != -1));

        // Get the ally team's Health information
        PlayerContainer[] temp = manager.GetMyTeam(myTeam);
        if(temp != null) {
            Debug.Log ("Temp is not null, player has a team");
            List<Health> tempHp = new List<Health>();
            for(int i=0; i<temp.Length; i++) {
                if(temp[i] != null) {
                    // Force this player into the first position of the array and everyone else
                    // in the order in which they are were added in the PlayerDataManager
                    if(temp[i].m_player == Network.player) {
                        Debug.Log ("Added");
                        tempHp.Insert(0, temp[i].m_health);
                    } else {
                        Debug.Log ("Added");
                        tempHp.Add(temp[i].m_health);
                    }
                }
            }
            m_allyHp = tempHp.ToArray();
            m_allyPercentages = new float[m_allyHp.Length];
            tempHp.Clear();
            tempHp.TrimExcess();
        } else {
            Debug.Log("Bad team number given, no ally team data returned.");
        }

        // Get the other team's Health information
        /*temp = manager.GetEnemyTeam(myTeam);
        if(temp[0] != null) {
            List<Health> tempHp = new List<Health>();
            for(int i=0; i<temp.Length; i++) {
                if(temp[i] != null) {
                    Debug.Log ("Added");
                    tempHp.Add(temp[i].m_health);
                }
            }
            m_enemyHp = tempHp.ToArray();
            m_enemyPercentages = new float[m_enemyHp.Length];
        } else {
            Debug.Log("No enemy team data returned.");
        }

        initialized = true;

        // Calculate everyone's health
        CalculateHealthPercentages();*/
    }