Example #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (!shot)
        {
            return;
        }

        if (collision.CompareTag("Enemy") && IsMoving())
        {
            Vector2 velocity = rb.velocity * knockbackForceMultiplier;

            collision.GetComponent <Enemy>().OnHit(velocity);
            shaker.ShakeCamera(0.3f);

            if (light.enabled)
            {
                FindObjectOfType <ScoreManager>().FireArrowHit();
                SetParent(collision.transform);
            }
            else
            {
                rb.velocity = Vector2.zero;
            }
        }

        TestFireHit(collision.tag, collision.gameObject);
    }
    IEnumerator StopTime()
    {
        Time.timeScale = 0.2f;
        yield return(new WaitForSecondsRealtime(0.2f));

        shaker.ShakeCamera(0.2f);
        Time.timeScale = 1;
    }
Example #3
0
    public void OnHit(float damage)
    {
        shaker.ShakeCamera(0.3f);
        particleSystem.Play();

        sanity -= damage;
        sanity  = Mathf.Clamp(sanity, 0f, 100f);
        PlaySound(hitSound);
    }
    private void Update()
    {
        SuperAmount = Mathf.Clamp(SuperAmount, 0, MaxSuperAMount);
        if (isDead && !animator.GetCurrentAnimatorStateInfo(0).IsName("die"))
        {
            //play death animation
            cameraShaker.ShakeCamera(shakingDuration);
            animator.SetTrigger("TriggerDeath");
            return;
        }
        if (DisableInput)
        {
            Time.timeScale = 1;
            return;
        }


        if (SuperAmount > 0)
        {
            if ( IsIdle && Input.GetButton("Charge"))
            {
                ChargeThreshold += 1;
                preChargeParticles.SetActive(true);
            }
            if (ChargeThreshold >= MaxChargeThreshold)
            {
                preChargeParticles.SetActive(false);
                IsChangingSpecial = true;
                animator.SetBool("isCharging", true);
                if (IsChangingSpecial)
                {
                    SuperAmount -= ChargeRate;
                    superBuffer += ChargeRate;

                    if (superBuffer >= SuperHealthCost)
                    {
                        //Add life after we have spent enough super (SuperHealthCost)
                        healthManager.Addlife(1);
                        //Reset buffer
                        superBuffer = 0;
                    }

                }
            }
        }

        if (Input.GetButtonUp("Charge") || (SuperAmount <= 0 && superBuffer <=0 ) || !IsIdle)
        {
            preChargeParticles.SetActive(false);
            if (superBuffer != 0)
            {
                SuperAmount += superBuffer;
                superBuffer = 0;
            }
            ChargeThreshold = 0;
            animator.SetBool("isCharging", false);
        }

        if (isSlowTime)
        {
            Time.timeScale = 0.1f;
            if (slowmoDuration > 0)
            {
                slowmoDuration -= 1;
            }
            else {
                isSlowTime = false;
                Time.timeScale = 1;
                slowmoDuration = _slowmoDuration;
            }

        }
        //Set axis to the direction pressed in the input
        xaxis = Input.GetAxisRaw("Horizontal") * moveSpeed;

        //animation handling for running
        if (xaxis != 0)
        {
            animator.SetBool("isRunning", true);
        }
        else
        {
            animator.SetBool("isRunning", false);
        }

        //If Jump button is pressed, verifu if not jumping or falling and animate appropriately
        //Bools are often used to transfer input from Update to fixedupdate to avoid glitches
        if (Input.GetButtonDown("Jump") && (!animator.GetBool("isFalling") && !animator.GetBool("isJumping")))
        {
            animator.SetBool("isFalling", false);
            animator.SetBool("isJumping", true);
            JumpPressed = true;
        }
        //Check if character is jumping and stop
        if (Input.GetButtonUp("Jump") && animator.GetBool("isJumping"))
        {
            JumpReleased = true;
        }
        //flip player based on running direction
        if (xaxis > 0 && !facingRight)
        {
            Flip();

        }
        else if (xaxis < 0 && facingRight)
        {
            Flip();
        }

        //handle fire button
        if (Input.GetButtonDown("Fire1"))
        {
            //Directional attack
            if (Input.GetAxisRaw("Vertical") > 0)
            {
                animator.SetTrigger("AttackUpTrigger");

            }
            else if (Input.GetAxisRaw("Vertical") < 0 && (animator.GetBool("isFalling") || animator.GetBool("isJumping")))
            {
                animator.SetTrigger("AttackDownTrigger");
            }
            else
            {
                animator.SetTrigger("AttackTrigger");
            }
        }
    }