Exemplo n.º 1
0
    // pickup for healing objects and keys
    void OnTriggerEnter2D(Collider2D collider)
    {
        //if the next line is here, the sound is played
        //FindObjectOfType<AudioManager>().PlayMusic("pickup");

        if (collider.gameObject.tag == "energia")
        {
            FindObjectOfType <AudioManager>().PlayMusic("pickup");
            HP = Mathf.Min(HP + healingHP, MaxHP);
            float scaled = HP / MaxHP;
            HPImage.fillAmount = scaled;
            HPImage.color      = Color.Lerp(HPempty, HPfull, scaled);

            collider.gameObject.SetActive(false);
        }

        if (collider.gameObject.tag == "shield")
        {
            collider.gameObject.SetActive(false);
            FindObjectOfType <AudioManager>().PlayMusic("pickup");

            if (PlayerPrefs.GetInt("shieldUpgrade") == 0)
            {
                PlayerPrefs.SetInt("shieldUpgrade", 1);
                MaxHP = 200;
                HP    = MaxHP;

                GameObject.Find("HPImage").SetActive(false);
                HPImageUpgraded.SetActive(true);
                HPImage = GameObject.Find("HealthBarUpgraded").GetComponent <Image>();

                float scaled = HP / MaxHP;
                HPImage.fillAmount = scaled;
                HPImage.color      = Color.Lerp(HPempty, HPfull, scaled);
            }
        }
    }
Exemplo n.º 2
0
    void Awake()
    {
        // pause button panel
        try {
            pausePanel   = GameObject.FindGameObjectsWithTag("PauseMenu")[0];
            pauseToggles = GameObject.FindGameObjectsWithTag("PauseToggles")[0];
            winButtons   = GameObject.FindGameObjectsWithTag("winButtons")[0];

            lossPanel = GameObject.FindGameObjectsWithTag("LosePanel")[0];
            // text object for HP
            //HPtext = GameObject.Find("HP text").GetComponent<Text>();
            HPImage = GameObject.Find("HealthBar").GetComponent <Image>();

            // flip controls toggle
            flipControlsToggle = GameObject.Find("FlipControlsToggle").GetComponent <Toggle>();
            flipControls       = flipControlsToggle.isOn;

            // braking toggle
            brakingEnableToggle = GameObject.Find("BrakingEnableToggle").GetComponent <Toggle>();
            brakingEnable       = brakingEnableToggle.isOn;

            mainCamera = GameObject.Find("Main Camera");
        } catch {
            Debug.Log("Some gameobject was not found.");
        }

        if (PlayerPrefs.GetInt("shieldUpgrade") == 1)
        {
            MaxHP = 200;
            HP    = MaxHP;

            GameObject.Find("HPImage").SetActive(false);
            HPImageUpgraded.SetActive(true);
            HPImage = GameObject.Find("HealthBarUpgraded").GetComponent <Image>();
        }

        rb = gameObject.GetComponent <Rigidbody2D>() as Rigidbody2D;
        rb.centerOfMass = com;
        HP        = 100;
        MaxHP     = HP;
        healingHP = 50;
        Debug.Log("HP: " + HP);

        pausePanel.SetActive(false);
        pauseToggles.SetActive(false);
        lossPanel.SetActive(false);
        winButtons.SetActive(false);

        brakingEnableToggle.isOn = PlayerPrefs.GetInt("brakeToggle") != 0;
        flipControlsToggle.isOn  = PlayerPrefs.GetInt("flipToggle") != 0;

        // give speed scales a prescale so it's easier to compare them
        speedScale         /= 100;
        rotationSpeedScale /= 100;
        brakingScale       /= 100;

        flipControls  = flipControlsToggle.isOn;
        brakingEnable = brakingEnableToggle.isOn;

        gameOn = true;

        flameTextureR.SetActive(false);
        flameTextureL.SetActive(false);
        flameTextureR_F.SetActive(false);
        flameTextureL_F.SetActive(false);
    }