Exemplo n.º 1
0
 public void Shoot()
 {
     shootWave.Shoot(transform.position, shotLength, transform.right);
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (isPaused)
        {
            return;
        }

        CheckGrounded();
        UpdateAimDirection();
        Vector2 controllerRightStick = Vector2.zero;

        float controllerMovement = Input.GetAxis("DpadHorizontal");

        if (controllerMovement == 0)
        {
            controllerMovement = Input.GetAxis("Horizontal");
        }

        float horizontalMovement = myRbody.velocity.x;

        if (!grounded)
        {
            canJumpTimer += Time.deltaTime;
        }
        else
        {
            canJumpTimer = 0;
        }

        if (Input.GetAxis("ShootJump") >= 0)
        {
            shootReset = true;
        }
        if (Input.GetAxis("ShootJump") <= 0)
        {
            jumpReset = true;
        }

        if (Input.GetAxis("Jump") == 0)
        {
            jump2Reset = true;
        }

        if (Input.GetAxis("Shoot") == 0)
        {
            shoot2Reset = true;
        }


        if ((Input.GetKeyDown(KeyCode.W) || (Input.GetAxis("Jump") > 0.1f && jump2Reset) || (Input.GetAxis("ShootJump") > 0.1f && jumpReset)) && (grounded || canJumpTimer < 0.1f))
        {
            if (Input.GetAxis("ShootJump") > 0.1f)
            {
                jumpReset = false;
            }
            if (Input.GetAxis("Jump") > 0.1f)
            {
                jump2Reset = false;
            }

            Jump();
            holdJump = true;
        }
        if (Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp(KeyCode.W) || myRbody.velocity.y < 0)
        {
            holdJump = false;
        }
        if (Input.GetKey(KeyCode.A) || controllerMovement < 0)
        {
            if (grounded)
            {
                //myAnimator.SetBool("Landing", false);
                myAnimator.SetBool("Walking", true);
            }
            else
            {
                myAnimator.SetBool("Walking", false);
            }
            spriteRenderer.transform.localScale    = new Vector3(-Mathf.Abs(spriteRenderer.transform.localScale.x), spriteRenderer.transform.localScale.y, 0);
            spriteRenderer.transform.localPosition = new Vector3(Mathf.Abs(spriteRenderer.transform.localPosition.x), spriteRenderer.transform.localPosition.y, 0);

            horizontalMovement -= playerInput.Acceleration * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.D) || controllerMovement > 0)
        {
            if (grounded)
            {
                //myAnimator.SetBool("Landing", false);
                myAnimator.SetBool("Walking", true);
            }
            else
            {
                myAnimator.SetBool("Walking", false);
            }

            spriteRenderer.transform.localScale    = new Vector3(Mathf.Abs(spriteRenderer.transform.localScale.x), spriteRenderer.transform.localScale.y, 0);
            spriteRenderer.transform.localPosition = new Vector3(-Mathf.Abs(spriteRenderer.transform.localPosition.x), spriteRenderer.transform.localPosition.y, 0);

            horizontalMovement += playerInput.Acceleration * Time.deltaTime;
        }

        if (!Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
        {
            myAnimator.SetBool("Walking", false);
            if (grounded)
            {
                if (horizontalMovement < 0)
                {
                    horizontalMovement += Mathf.Min(playerInput.drag * Time.deltaTime, Mathf.Abs(horizontalMovement));
                }
                else
                {
                    horizontalMovement -= Mathf.Min(playerInput.drag * Time.deltaTime, Mathf.Abs(horizontalMovement));
                }
            }
            else
            {
                horizontalMovement -= Mathf.Min(playerInput.airDrag * Time.deltaTime, Mathf.Abs(horizontalMovement));
            }
        }
        shootTimer += Time.deltaTime;
        if (rubrixFollower)
        {
            if (shootTimer >= playerInput.shootCooldown - 0.3f && rubrixFollower.grayScale == 1)
            {
                rubrixFollower.SetGrayScale(0);
            }

            if (shootTimer >= 0.2f && shootTimer < playerInput.shootCooldown - 0.1f && rubrixFollower.grayScale == 0)
            {
                rubrixFollower.SetGrayScale(1);
            }
        }
        if ((Input.GetMouseButton(0) || Input.GetKeyDown(KeyCode.Space) || (Input.GetAxis("Shoot") > 0.2f && shoot2Reset) || (Input.GetAxis("ShootJump") < -0.1f && shootReset)) && shootTimer >= playerInput.shootCooldown && playerInput.canShoot)
        {
            //rubrixFollower.SetGrayScale(1);
            if (Input.GetAxis("ShootJump") < -0.1f)
            {
                shootReset = false;
            }

            if (Input.GetAxis("Shoot") > 0.2f)
            {
                shoot2Reset = false;
            }

            //mainCam.SendMessage("AddShake", 0.4f, SendMessageOptions.DontRequireReceiver);
            //gameObject.SendMessage("AddShake", 0.7f, SendMessageOptions.DontRequireReceiver);

            //shootWave.startOffset = aimDirection.normalized *  ((transform.lossyScale.x/2 * Mathf.Sqrt(2)) + (shootWave.wave.transform.lossyScale.magnitude/2) + 0.01f);
            int          layerMask = ~(1 << LayerMask.NameToLayer("Projectile") | 1 << LayerMask.NameToLayer("Player"));
            Vector3      offset    = aimDirection;
            RaycastHit2D hit       = Physics2D.Raycast(transform.position, aimDirection, aimDirection.magnitude, layerMask);
            if (hit && hit.collider.gameObject)
            {
                offset = (hit.point + (Vector2)(-aimDirection.normalized * shootWave.wave.transform.lossyScale.magnitude / 2) - (Vector2)transform.position);
                //Debug.Log("alternate");
            }
            if (rubrixFollower)
            {
                rubrixFollower.Fire();
            }

            if (!hit || hit.collider.CompareTag("BounceableWall") || hit.collider.isTrigger)
            {
                shootWave.Shoot(transform.position + offset, projectileSettings.projectileLength, aimDirection, 2);
            }
            myAudio.PlayOneShot(sounds.laserSound, sounds.laserVolume);
            shootTimer = 0;
        }

        if (!grounded && myRbody.velocity.y < 0)
        {
            myAnimator.SetBool("Falling", true);
            myAnimator.SetBool("Jumping", false);
        }

        horizontalMovement = Mathf.Clamp(horizontalMovement, -playerInput.movementSpeed, playerInput.movementSpeed);
        myRbody.velocity   = new Vector2(horizontalMovement, Mathf.Min(myRbody.velocity.y, playerInput.terminalVelocity)) + forceToApply;
        lastFrameVelocity  = myRbody.velocity;
        forceToApply       = Vector2.zero;
    }