Ejemplo n.º 1
0
    void Update()
    {
        animator.SetBool("grounded", grounded);
        animator.SetBool("walking", walking);
        animator.SetBool("crouching", crouching);
        animator.SetBool("sliding", sliding);
        animator.SetBool("dashing", dashing);
        animator.SetBool("falling", falling);
        animator.SetBool("wall", stuckToWall);
        animator.SetBool("onLadder", onLadder);
        animator.SetBool("jumpingThrough", jumpingThrough);

        if (timer > 0f)
        {
            timer -= Time.deltaTime;
        }

        if (timer < 0f)
        {
            timer = 0f;
        }

        if (timer == 0f)
        {
            WSVibrator.Cancel();
        }

        if (orient == null)
        {
            orient = GameObject.Find("KingOrient");
        }

        if (goodSpawn == null)
        {
            goodSpawn = GameObject.Find("EndSpawnBack");
        }

        if (attackTimer > 0f)
        {
            attackTimer -= Time.deltaTime;
        }

        if (attackTimer == 0f && timedFire)
        {
            timedFire = false;
            fire      = false;
        }

        if (nextFire > 0f)
        {
            nextFire -= Time.deltaTime;
        }

        if (attackTimer < 0f)
        {
            attackTimer = 0f;
        }

        if (staffTimer < 0f)
        {
            staffTimer = 0f;
        }

        if (staffTimer > 0f)
        {
            staffTimer -= Time.smoothDeltaTime;
        }

        if (staffTimer == 0)
        {
            staffClicks = 0;
        }

        if (nextFire < 0f)
        {
            nextFire = 0f;
        }

        Vector2 pos = transform.position;

        if (facingRight)
        {
            frontCheckTop.transform.position = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));
            frontCheckBot.transform.position = new Vector2(pos.x + boxCollider.offset.x + (boxCollider.size.x / 2) + 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius / 2));
        }

        else
        {
            frontCheckTop.transform.position = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2), pos.y + boxCollider.offset.y + (boxCollider.size.y / 2));
            frontCheckBot.transform.position = new Vector2(pos.x + boxCollider.offset.x - (boxCollider.size.x / 2) - 0.1f, pos.y + boxCollider.offset.y - (boxCollider.size.y / 2) - (circleCollider.radius / 2));
        }

        if (!stop)
        {
            hor = CFInput.GetAxis("Horizontal");
            animator.SetFloat("horizontal", Mathf.Abs(hor));
        }

        animator.SetFloat("xSpeed", Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x));
        animator.SetFloat("ySpeed", GetComponent <Rigidbody2D>().velocity.y);

        if (!OnPlatform())
        {
            groundCollider = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayer);
        }

        if (keepVelocityOnGround && groundedXVelocity > 0)
        {
            if (groundedTimer > 0)
            {
                groundedTimer -= Time.deltaTime;
            }

            else
            {
                groundedXVelocity = 0;
            }
        }

        if (groundCollider && !jumpingThrough)
        {
            if (keepVelocityOnGround && !grounded)
            {
                groundedXVelocity = GetComponent <Rigidbody2D>().velocity.x;
                groundedTimer     = groundedVelocityTime;
            }
            grounded = true;
            jumping  = false;
            if (rotateOnSlope && !OnPlatform())
            {
                transform.rotation = groundCollider.transform.localRotation;
            }
            if (falling)
            {
                animator.SetTrigger("stateComplete");
            }
            falling = false;
        }

        else
        {
            transform.rotation = normalRotation;
            grounded           = false;
        }

        if ((hor > 0 && !facingRight) || (hor < 0 && facingRight) || flipAgain)
        {
            Flip();
        }

        if (Staff)
        {
            if (pickup.staffAmmo > 0f && staffClicks == 1 && !staffFired)
            {
                if (staffTimer < 0.3f)
                {
                    Vib100();
                    isAttacking = true;
                    fire        = true;
                    animator.SetBool("StaffFire", true);
                    GetComponent <AudioSource>().PlayOneShot(staffShot, 1.0f);
                    GameObject      newBullet = Instantiate(staffBullet);
                    StaffController bullCon   = newBullet.GetComponent <StaffController>();
                    bullCon.playerObject = gameObject;
                    bullCon.StaffShoot();
                    newBullet.transform.position = staffBulletSpawn.position;
                    pickup.staffAmmo--;
                    staffFired = true;
                }
            }
        }

        if (CFInput.GetButtonDown("Fire1"))
        {
            Fire();
        }

        if (CFInput.GetButton("Fire1") && Machinegun)
        {
            machinegunBulletSpawn = GameObject.Find("MachineGunSpawnPoint").transform;
            if (!onLadder && !stuckToWall)
            {
                if (nextFire == 0f && pickup.machinegunAmmo > 0f)
                {
                    Vib50();
                    isAttacking = true;
                    nextFire    = machinegunFireRate;
                    animator.SetBool("MachineGunFire", true);
                    GetComponent <AudioSource>().PlayOneShot(machinegunShot, 1.0f);
                    GameObject           newBullet = Instantiate(machinegunBullet);
                    GameObject           newKick   = Instantiate(machinegunKick);
                    MachineGunController bullCon   = newBullet.GetComponent <MachineGunController>();
                    ParticleFlip         kickCon   = newKick.GetComponent <ParticleFlip>();
                    bullCon.playerObject = gameObject;
                    kickCon.playerObject = gameObject;
                    bullCon.MachineGunShoot();
                    kickCon.MachineGunShoot();
                    newBullet.transform.position = machinegunBulletSpawn.position;
                    newKick.transform.position   = machinegunBulletSpawn.position;
                    pickup.machinegunAmmo--;
                }

                else if (pickup.machinegunAmmo == 0f)
                {
                    isAttacking = false;
                    animator.SetBool("MachineGunFire", false);
                    GetComponent <AudioSource>().PlayOneShot(outOfAmmo);
                }
            }
        }

        if (CFInput.GetButtonUp("Fire1") && Machinegun)
        {
            isAttacking = false;
            animator.SetBool("MachineGunFire", false);
        }
    }