Esempio n. 1
0
    //--------------------------------------------------------------//
    //-------------------------method 5: attack---------------------//
    //--------------------------------------------------------------//
    void attack()
    {
        //two key variables are attackCounter and timeSinceAttack
        timeSinceAttack = (int)(Time.realtimeSinceStartup - attackTime);
        //attacks:attack1;attack2;attack3

        if (attackCounter == 0 && timeSinceAttack >= 0)
        {
            attackTime    = Time.realtimeSinceStartup;
            attackCounter = 1;
        }
        else if (attackCounter == 1 && timeSinceAttack >= 2 /** change to increase time of attack*/)
        {
            attackTime    = Time.realtimeSinceStartup;
            attackCounter = 2;
            // animation required
            Debug.Log("attack1");
            playerScript.setHealth(-20);
        }
        else if (attackCounter == 2 && timeSinceAttack >= 1 /** change to increase time of attack*/)
        {
            attackTime    = Time.realtimeSinceStartup;
            attackCounter = 3;
            // animation required
            Debug.Log("attack2");
            playerScript.setHealth(-30);
        }
        else if (attackCounter == 3 && timeSinceAttack >= 1 /** change to increase time of attack*/)
        {
            attackTime    = Time.realtimeSinceStartup;
            attackCounter = 0;
            // animation required
            Debug.Log("attack3");
            playerScript.setHealth(-50);
        }
    }