Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (health > maxHealth)
        {
            health = maxHealth;
        }
        if (ammo > maxAmmo)
        {
            ammo = maxAmmo;
        }

        if (ammo > 0)
        {
            haveAmmo = true;
            if (noAmmoInd)
            {
                noAmmoInd.SetActive(false);
            }
        }
        else
        {
            haveAmmo = false;
            if (noAmmoInd)
            {
                noAmmoInd.SetActive(true);
            }
        }

        if (health <= 0)
        {
            GameManager.ChangeLevel(deathSceneIndex);
            health = maxHealth;
        }

        if (healthDisplayObj)
        {
            healthDisplayObj.WriteHealth((int)health);
        }
        else
        {
            try
            {
                healthDisplayObj = FindObjectOfType <HealthDisplay>();
            }
            catch (NullReferenceException e)
            { }
        }

        if (ammoDisplayObj)
        {
            ammoDisplayObj.WriteAmmo(ammo);
        }
        else
        {
            try
            {
                ammoDisplayObj = FindObjectOfType <AmmoDisplay>();
            }
            catch (NullReferenceException e)
            { }
        }
    }