HealthBarController.setHealth C# (CSharp) Method

setHealth() public method

public setHealth ( float newHealth ) : void
newHealth float
return void
    public void setHealth(float newHealth)
    {
        //while (newHealth==0 && count < 10000) {count++; yield return null;}
        health = newHealth;

        if (hbProgress != null){
            float originalValue = hbProgress.GetComponent<Renderer>().bounds.min.x;
            float calculate = Mathf.Clamp (health / divider, 0f, 1f);
            hbProgress.transform.localScale = new Vector3 (calculate, 1f, 1f);
            float newValue = hbProgress.GetComponent<Renderer>().bounds.min.x;
            float difference = newValue - originalValue;
            hbProgress.transform.Translate(new Vector2 (-difference, 0));
        }
    }

Usage Example

Example #1
0
    void Start()
    {
        health = 100;
        score  = 0;
        updateScore();
        gameOver = false;



        GameObject gameControlObject = GameObject.FindWithTag("ui");

        if (gameControlObject != null)
        {
            gameOverScript = gameControlObject.GetComponent <GameOverScript>();
            healthInstance = healthBarController.GetComponent <HealthBarController>();
            healthInstance.setMaxHealth(100.0f);
            healthInstance.setHealth(100.0f);
        }
        if (gameControlObject == null)
        {
            Debug.Log("Sorry ,Couldn't find object");
        }
        StartCoroutine(SpawnWaves());
        StartCoroutine(spawnPowerUps());
    }
All Usage Examples Of HealthBarController::setHealth
HealthBarController