Example #1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Dev"))
        {
            SceneManager.LoadScene("MageTest", LoadSceneMode.Single);
        }
        UpdateAnimator();
        if (Input.GetButtonDown("Attack") && !charging)
        {
            charging = true;
            pcBase.setCanMove(false);
        }

        if (Input.GetButtonDown("Special") && specialtimer > specialtimerGoal && !charging)
        {
            pcBase.setSpeed(6);
            specialtimer = 0;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Dev"))
        {
            SceneManager.LoadScene("RangerTest", LoadSceneMode.Single);
        }
        UpdateAnimator();
        if (Input.GetButtonDown("Attack") && !attacking && !usingSpecial)
        {
            attack();
        }

        if (Input.GetButtonDown("Special") && !usingSpecial && !attacking)
        {
            usingSpecial = true;
            pcBase.setCanMove(false);
            if (pcBase.facingDirection == 0)
            {
                currentShield = Instantiate(shieldUp, body.position, new Quaternion());
            }
            if (pcBase.facingDirection == 1)
            {
                currentShield = Instantiate(shieldRight, body.position, new Quaternion());
            }
            if (pcBase.facingDirection == 2)
            {
                currentShield = Instantiate(shieldDown, body.position, new Quaternion());
            }
            if (pcBase.facingDirection == 3)
            {
                currentShield = Instantiate(shieldLeft, body.position, new Quaternion());
            }
        }

        if (usingSpecial && Input.GetButtonUp("Special"))
        {
            usingSpecial = false;
            pcBase.setCanMove(true);
            Destroy(currentShield);
        }
    }
    void FixedUpdate()
    {
        attacktimer  += Time.deltaTime;
        specialtimer += Time.deltaTime;
        if (numOfFirewalls < 5)
        {
            firewallTimer += Time.deltaTime;
        }

        if (numOfFirewalls < 5 && firewallTimer > 2.6)
        {
            firewallTimer  = 0;
            numOfFirewalls = numOfFirewalls + 1;
        }

        if (charging)
        {
            chargetimer += Time.deltaTime;
        }

        if (chargetimer >= chargetimerGoal && !charged)
        {
            source.PlayOneShot(charge, 0.2f);
            charged = true;
        }

        //if the attack is over, say we are no longer attacking and we can move again
        if (attacking && attacktimer > 0.25f)
        {
            attacking = false;
            if (!Input.GetButton("Attack"))
            {
                pcBase.setCanMove(true);
            }
            else
            {
                charging = true;
            }
        }

        //exit out of charging if attack is released before it's finished
        if (charging && !Input.GetButton("Attack") && !charged)
        {
            charging    = false;
            chargetimer = 0;
            pcBase.setCanMove(true);
        }
        else if (charging && !Input.GetButton("Attack") && charged) //preform charged attack
        {
            charged  = false;
            charging = false;
            //attack();
            chargetimer = 0;
            pcBase.setCanMove(true);

            if (pcBase.facingDirection == 0)
            {
                Vector2 shootPosition = body.position;
                shootPosition.y += 0.7f;
                GameObject  clone     = (GameObject)Instantiate(chargeFireball, shootPosition, new Quaternion());
                Rigidbody2D cloneBody = clone.GetComponent <Rigidbody2D>();
                cloneBody.rotation = 90;
            }
            if (pcBase.facingDirection == 1)
            {
                Vector2 shootPosition = body.position;
                shootPosition.x += 0.7f;
                GameObject  clone     = (GameObject)Instantiate(chargeFireball, shootPosition, new Quaternion());
                Rigidbody2D cloneBody = clone.GetComponent <Rigidbody2D>();
                cloneBody.rotation = 0;
            }
            if (pcBase.facingDirection == 2)
            {
                Vector2 shootPosition = body.position;
                shootPosition.y -= 0.7f;
                GameObject  clone     = (GameObject)Instantiate(chargeFireball, shootPosition, new Quaternion());
                Rigidbody2D cloneBody = clone.GetComponent <Rigidbody2D>();
                cloneBody.rotation = 270;
            }
            if (pcBase.facingDirection == 3)
            {
                Vector2 shootPosition = body.position;
                shootPosition.x -= 0.7f;
                GameObject  clone     = (GameObject)Instantiate(chargeFireball, shootPosition, new Quaternion());
                Rigidbody2D cloneBody = clone.GetComponent <Rigidbody2D>();
                cloneBody.rotation = 180;
            }
        }
    }