示例#1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Arrrow Arrow = collision.gameObject.GetComponent <Arrrow>();

        if (Arrow == null)
        {
            return;
        }
        Health -= 1;
    }
示例#2
0
    void Update()
    {
        speedVector = rb2d.velocity;
        stopVector  = rb2d.velocity;
        fallVector  = rb2d.velocity;
        teleVector  = rb2d.position;

        isGrounded = doesGround.IsTouchingLayers(isGroundedLayer);
        //Physics2D.OverlapArea(new Vector2(transform.position.x - groundCheckRadious, transform.position.y - groundCheckRadious),
        //new Vector2(transform.position.x + groundCheckRadious, transform.position.y - groundCheckRadious), isGroundedLayer);

        if (rb2d.position.x <= -tp)
        {
            teleVector.x       = tp;
            transform.position = teleVector;
        }
        if (rb2d.position.x >= tp)
        {
            teleVector.x       = -tp;
            transform.position = teleVector;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) && isGrounded)
        {
            crouch = true;
            anim.Play("Crouching");
        }
        if (Input.GetKeyUp(KeyCode.LeftShift))
        {
            crouch = false;
            anim.Play("Idle");
        }

        if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
        {
            rb2d.AddForce(Vector3.up * JumpForce);
            anim.Play("Jumping");
            Audio.clip = jump;
            Audio.Play();
            Debug.Log("jump");
        }
        if (rb2d.velocity.y <= 0 && !isGrounded)
        {
            //rb2d.AddForce(Vector3.down * 10);
            //fallVector.y = fall;
            rb2d.velocity = fallVector;
            anim.Play("Falling");
            fell = true;
        }
        else if (rb2d.velocity.y <= 0 && isGrounded && fell)
        {
            anim.Play("Idle");
            fell = false;
        }
        if (Input.GetKeyDown(KeyCode.A))
        {
            speedVector.x = speed;
            rb2d.velocity = speedVector;
            if (isGrounded && !crouch)
            {
                anim.Play("Walking");
            }
            else if (crouch)
            {
                anim.Play("Crouching");
            }
        }
        if (Input.GetKeyUp(KeyCode.A))
        {
            stopVector.x  = stop;
            rb2d.velocity = stopVector;
            if (isGrounded && !crouch)
            {
                anim.Play("Idle");
            }
            else if (crouch)
            {
                anim.Play("Crouching");
            }
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            speedVector.x = -speed;
            rb2d.velocity = speedVector;
            if (isGrounded && !crouch)
            {
                anim.Play("Walking");
            }
            else if (crouch)
            {
                anim.Play("Crouching");
            }
        }
        if (Input.GetKeyUp(KeyCode.D))
        {
            stopVector.x  = stop;
            rb2d.velocity = stopVector;
            if (isGrounded && !crouch)
            {
                anim.Play("Idle");
            }
            else if (crouch)
            {
                anim.Play("Crouching");
            }
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            anim.Play("Shooting");
            a          = Instantiate(arrow, new Vector2(rb2d.position.x, rb2d.position.y), Quaternion.identity).GetComponent <Arrrow>();
            shot       = true;
            Audio.clip = pew;
            Audio.Play();
            Debug.Log("pew");
        }

        if ((rb2d.velocity.x < 0 && toRight) || (rb2d.velocity.x > 0 && !toRight))
        {
            toRight         = !toRight;
            SprtRndrr.flipX = !SprtRndrr.flipX;
        }

        if (shot)
        {
            a.speedVector.x = -speed;
            //shot = false;
            if (!toRight)
            {
                a.Flip(SprtRndrr.flipX);
                a.speedVector.x *= -1;
            }
        }


        /*if (!toRight) {
         *  AroSpeed *= -1;
         * }
         * if (toRight) {
         *  AroSpeed = 10;
         * }*/

        if (Health <= 0)
        {
            Destroy(gameObject);
        }
    }