예제 #1
0
    private void Update()
    {
        // Coyote time
        if (jumpTimer > 0)
        {
            jumpTimer -= Time.deltaTime;
        }
        if (groundedRemember > 0)
        {
            groundedRemember -= Time.deltaTime;
        }
        if (inputTimer > 0.0)
        {
            inputTimer -= Time.deltaTime;
        }

        if (groundDetector.IsGrounded() && jumpTimer <= 0)
        {
            groundedRemember = coyoteTime;
        }

        if (!GameManager.Instance.GetInputFreeze() && Input.GetKeyDown(KeyCode.Space))
        {
            inputTimer = inputRemerberTime;
        }

        if (inputTimer > 0.0f)
        {
            ExecuteJump();
        }

        if (groundDetector.IsGrounded())
        {
            playerAnim.SetBool("Falling", false);
        }

        if (myRigidbody.velocity.y < 0)
        {
            if (Mathf.Abs(myRigidbody.velocity.y) > 2.5f)
            {
                playerAnim.SetBool("Falling", true);
            }

            myRigidbody.velocity += Vector2.up * Physics2D.gravity.y * myRigidbody.gravityScale * (fallMultiplier - 1.0f) * Time.deltaTime;

            if (Mathf.Abs(myRigidbody.velocity.y) > maxFallSpeed)
            {
                myRigidbody.velocity = Vector2.up * -maxFallSpeed;
            }
        }
        else if (myRigidbody.velocity.y > 0 && !Input.GetButton("Jump"))
        {
            myRigidbody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1.0f) * Time.deltaTime;
        }
        else if (myRigidbody.velocity.y > 0 && Mathf.Abs(myRigidbody.velocity.y) < jumpSpeed * 0.75)
        {
            myRigidbody.velocity += Vector2.up * Physics2D.gravity.y * (lowJumpMultiplier - 1.0f) * Time.deltaTime;
        }
    }
예제 #2
0
    private void Update()
    {
        if (collected == 1)
        {
            if (!playerHealth.IsAlive())
            {
                collected = 0;
                spriteRenderer.enabled = true;
                Reset();
                soulParticles.Play();
                myLight.gameObject.SetActive(true);
                myLight.intensity = intensity;
                GameManager.Instance.CollectableReset();
            }
            else if (groundDetector.IsGrounded())
            {
                collected = 2;
                timer     = 0.0f;
            }
        }
        if (collected == 2)
        {
            timer += Time.deltaTime;

            myLight.intensity = intensity - timer / brokenTime * intensity;
            if (timer > brokenTime)
            {
                gameObject.SetActive(false);
                myLight.gameObject.SetActive(false);
            }
        }
    }
예제 #3
0
    // Update is called once per frames
    void Update()
    {
        var horizontal = Input.GetAxis("Horizontal");
        var jump       = Input.GetButton("Jump");
        var hit        = Input.GetButtonDown("Fire1");

        if (hit)
        {
            Hit();
        }
        else
        {
            var direction = new Vector3(horizontal * speed, body.velocity.y, 0f);
            if (direction.magnitude >= 0.1f)
            {
                var targetAngle = Mathf.Atan2(direction.x, 0f) * Mathf.Rad2Deg;

                transform.rotation = Quaternion.Euler(0f, targetAngle, 0f);
                body.velocity      = direction;
            }
            if (jump && groundDetector.IsGrounded())
            {
                body.velocity = new Vector3(body.velocity.x, jumpForce, body.velocity.z);
            }
        }
        if (comboCounter > 0f)
        {
            comboCounter -= Time.deltaTime;
        }
        else if (comboCounter <= 0f)
        {
            comboCounter = 0;
            isReload     = false;
        }
        UpdateAnimator(horizontal);
        //animator.SetFloat("Turn", Mathf.Atan2(direction.x, direction.y), 0.1f, Time.deltaTime);
    }
예제 #4
0
    private void Update()
    {
        if (!playerHealth.IsAlive())
        {
            StopParticles();
        }

        if (GameManager.Instance.GetInputFreeze())
        {
            return;
        }

        if (Input.GetMouseButtonUp(0) && throwable == null && !thrown && !stopped)
        {
            throwable = InternalThrow(throwablePrefab);
            playerHealth.SetThrowable(throwable);
            if (!infinite)
            {
                thrown = true;
            }
            orb.gameObject.SetActive(false);
            aimTarget.SetActive(false);

            playerAnim.SetTrigger("Throw");
            playerAnim.SetBool("Casting", false);

            startCastingParticles.Play();
            castingParticles.Stop();
            soundEmitter.SetParameter("Lanzar", 1);

            if (playingSound)
            {
                playingSound = false;
            }
        }
        else if (Input.GetMouseButtonUp(0) && throwable != null && !stopped)
        {
            throwable.Teleport(gameObject);
            playerHair.Teleport();
            orb.Reset();
            orb.Teleport();

            playerAnim.SetTrigger("Appear");
            appearParticles.Play();

            movement.ClearForces();
            movement.SetMovementScaleForTTime(movementScaleOnTeleport, timeToWaitOnTeleport);
            jump.SetGravityScaleForTTime(gravityScaleOnTeleport, timeToWaitOnTeleport);
            Destroy(throwable.gameObject);

            RuntimeManager.PlayOneShotAttached("event:/Teleport", this.gameObject);
        }
        else if (Input.GetMouseButtonDown(1) && throwable != null && !stopped)
        {
            orb.Reset();
            Destroy(throwable.gameObject);
            throwable = null;
            RuntimeManager.PlayOneShotAttached("event:/recuperar orbe", this.gameObject);
            thrown = false;
        }
        else if (Input.GetMouseButton(0) && throwable == null && !thrown && !stopped)
        {
            orb.GetCloser(orbSpawn);
            aimTarget.SetActive(true);
            Vector3 direction = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - orbSpawn.position);
            direction.z = 0;
            aimTarget.transform.position = orbSpawn.position + direction.normalized * aimOffset;
            aimTarget.transform.rotation = Quaternion.Euler(0.0f, 0.0f, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x));

            playerAnim.SetBool("Casting", true);
            castingParticles.Play();
            soundEmitter.Event = "event:/lanzamiento";

            if (!playingSound)
            {
                soundEmitter.Stop();
            }

            soundEmitter.SetParameter("Lanzar", 0);
            soundEmitter.OverrideAttenuation = true;
            soundEmitter.OverrideMaxDistance = 500;

            if (!playingSound)
            {
                playingSound = true;
                soundEmitter.Play();
            }
        }
        else if (throwable == null && !thrown)
        {
            playerAnim.SetBool("Casting", false);

            if (playingSound)
            {
                playingSound = false;
                soundEmitter.Stop();
            }

            //orb.Reset();
            aimTarget.SetActive(false);
            castingParticles.Stop();
        }

        if (throwable == null && thrown && groundDetector.IsGrounded())
        {
            thrown = false;
            orb.Reset();

            startCastingParticles.Stop();
            castingParticles.Stop();
            throwParticles.Stop();
            appearParticles.Stop();
        }

        stopped = Time.timeScale == 0;
    }