Esempio n. 1
0
    //----------------------------------------------------------------------------||
    // Action Functions
    //----------------------------------------------------------------------------||

    /** Checks for cooldown. If no cooldown and an attack button is being pressed then perform the attack */
    void Attack(float dir)
    {
        // Cooldown
        if (currentCD > 0)
        {
            float CDRatio = 50 * currentCD / maxCD;
            if (CDBar != null)
            {
                CDBar.rectTransform.sizeDelta = new Vector2(50, CDRatio);
                //CDBar.rectTransform.localPosition = new Vector3(0, 25 - CDRatio / 2, 0);
                CDBar.rectTransform.localPosition = new Vector3(-26, 51 - CDRatio / 2, 0);
            }
            currentCD--;
            return;
        }
        if (CDBar != null)
        {
            CDBar.rectTransform.sizeDelta = new Vector2(0, 50);  // Clean up
        }
        if (currentCD == 0)
        {
            dirLocked = true;
            attacking = false;
            if (playerSword)
            {
                playerSword.FinishAttack();
            }
        }

        // Attack
        if (Input.GetMouseButtonDown(0) || Input.GetAxis("JoyAttack") < -0.5)
        {
            selectedSound = attackNoises[0];
            playerSound.PlayOneShot(selectedSound);
            previousDirection = HorizontalDirection;
            dirLocked         = false;
            attacking         = true;
            ActionAnim(Action.LIGHT_ATTACK);
            maxCD     = LIGHT_ATK_CD;
            currentCD = LIGHT_ATK_CD;
            if (playerSword)
            {
                playerSword.QuickAttack();
            }
        }
        if (Input.GetMouseButtonDown(1) || Input.GetAxis("JoyAttack") > 0.5)
        {
            dirLocked = false;
            attacking = true;
            ActionAnim(Action.HEAVY_ATTACK);
            maxCD     = HEAVY_ATK_CD;
            currentCD = HEAVY_ATK_CD;
            if (playerSword)
            {
                playerSword.PowerAttack();
            }

            selectedSound = attackNoises[1];
            playerSound.PlayOneShot(selectedSound);
        }
    }