setHealth() public method

public setHealth ( float newHealth ) : void
newHealth float
return void
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());
    }
Example #2
0
    protected new void Start()
    {
        base.Start();

        status = StatusType.Live;

        if (showHealthBar)
        {
            var hb = Instantiate(Resources.Load(configs.prefabPaths.uiHealthbar), new Vector3(transform.position.x, transform.position.y - transform.lossyScale.y), Quaternion.identity) as GameObject;
            hb.transform.parent = transform;
            healthBar           = hb.GetComponent <HealthBarController>();
            healthBar.setHealth(health);
            healthBar.divider = health;
            healthBar.yMargin = healthBarYMargin;
        }

        OnHit += (o) => {
            if (o.hits != null && System.Array.IndexOf(o.hits, this.GetType()) > -1)
            {
                decHealth(o.damage);
                spriteRenderer.color = Color.red;
                CancelInvoke("switchBackToOriginalColor");
                Invoke("switchBackToOriginalColor", .2f);
            }
        };

        build();
    }
Example #3
0
    // Start is called before the first frame update
    void Start()
    {
        health = 100;
        power  = 100;
        //gameOver = false;



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

        if (gameControlObject != null)
        {
            //gameOverScript = gameControlObject.GetComponent<GameOverScript>();
            healthInstance = healthBarController.GetComponent <HealthBarController>();
            powerInstance  = powerBarController.GetComponent <PowerBarController>();

            healthInstance.setMaxHealth(100.0f);
            healthInstance.setHealth(100.0f);

            powerInstance.setMaxPower(100.0f);
            powerInstance.setPower(100.0f);
        }
        if (gameControlObject == null)
        {
            Debug.Log("Sorry ,Couldn't find object");
        }
    }
Example #4
0
 public void decHealth(int by)
 {
     health -= by;
     if (OnHealthChanged != null)
     {
         OnHealthChanged(health);
     }
     healthBar.setHealth(health);
     if (health <= 0)          //DIE!!!
     {
         if (OnDie != null)
         {
             OnDie();
         }
         Destroy(gameObject);
     }
 }
Example #5
0
    public void usePotion(int healedAmount)
    {
        //Todo: comprobar si el jugador tiene pociones en su inventario.
        //^Como en el prototipo no se ha planificado crear un inventario ni objetos coleccionables, las pociones son infinitas.

        exitCombatMenu(); //Sale del slow motion para realizar la accion

        health = health + healedAmount;
        health = Mathf.Clamp(health, 0, maxHealth);
        healthBar.setHealth(health);

        //Todo: play heal FX

        //Accion realizada
        playerInput.SwitchCurrentActionMap("Player");

        //AUDIO
        AudioManager.engine.usePotion();
        //
    }
Example #6
0
 public void TakeDamage()
 {
     healthLevel = healthLevel - 10;
     audio.PlayOneShot(painSound);
     healthBar.setHealth(healthLevel);
 }
Example #7
0
 void updateHealth(float health2)
 {
     healthInstance.setHealth(health2);
 }
Example #8
0
    protected new void Start()
    {
        base.Start();

        status = StatusType.Live;

        if (showHealthBar) {
            var hb = Instantiate(Resources.Load(configs.prefabPaths.uiHealthbar),new Vector3(transform.position.x, transform.position.y - transform.lossyScale.y),Quaternion.identity) as GameObject;
            hb.transform.parent = transform;
            healthBar = hb.GetComponent<HealthBarController>();
            healthBar.setHealth(health);
            healthBar.divider = health;
            healthBar.yMargin = healthBarYMargin;
        }

        OnHit += (o) => {
            if (o.hits!=null && System.Array.IndexOf(o.hits, this.GetType()) > -1 ){
                decHealth(o.damage);
                spriteRenderer.color = Color.red;
                CancelInvoke("switchBackToOriginalColor");
                Invoke("switchBackToOriginalColor", .2f);
            }
        };

        build();
    }