Exemple #1
0
    void ControlMovement()
    {
        rb.velocity = new Vector2(h * speed, rb.velocity.y);
        if (js == JumpingStates.Start)
        {
            js          = JumpingStates.Impulse;
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            anim.SetBool("jump", true);
            isGrounded = false;
        }
        else if (js == JumpingStates.Air)
        {
            if (Physics2D.OverlapBox(left, areaCheck, 0, colLayers) || Physics2D.OverlapBox(right, areaCheck, 0, colLayers))
            {
                rb.velocity = new Vector2(0, rb.velocity.y);
            }
        }
        if (js != JumpingStates.Impulse && Physics2D.OverlapCircle(pos, .001f, colLayers))
        {
            isGrounded = true;
            if (js == JumpingStates.Air)
            {
                js = JumpingStates.None;
                anim.SetBool("jump", false);
            }
        }
        if (js == JumpingStates.Impulse)
        {
            js = JumpingStates.Air;
        }

        anim.SetBool("walking", h != 0 && js == JumpingStates.None);
    }
Exemple #2
0
    // Receive Inputs
    void Update()
    {
        if (!active)
        {
            return;
        }

        h = Input.GetAxis("Horizontal");

        if (js == JumpingStates.None && isGrounded && Input.GetButtonDown("Jump"))
        {
            js = JumpingStates.Start;
        }

        if (atkNum < comboDamage.Length + 1 && attackable && !shielding && !focus && Input.GetButtonDown("Fire1"))
        {
            Attack();
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            hud.TogglePause();
        }

        if (Input.GetButtonDown("Shield") && !focus)
        {
            EnableShield();
        }
        else if (Input.GetButtonUp("Shield"))
        {
            DisableShield();
        }

        if (Input.GetButtonDown("Focus") && isGrounded && !shielding && atkNum == 0)
        {
            ToggleFocus();
        }
    }
Exemple #3
0
 void Awake()
 {
     instance       = this;
     cam            = Camera.main.GetComponent <CameraController>();
     cam.target     = transform;
     sr             = GetComponent <SpriteRenderer>();
     rb             = GetComponent <Rigidbody2D>();
     col            = GetComponent <BoxCollider2D>();
     anim           = GetComponent <Animator>();
     source         = GetComponent <AudioSource>();
     knifeSr        = transform.GetChild(0).GetComponent <SpriteRenderer>();
     hud            = HudController.instance;
     shield         = transform.GetChild(1).gameObject;
     shieldCol      = shield.GetComponent <BoxCollider2D>();
     focusParticles = transform.GetChild(2).gameObject;
     js             = JumpingStates.None;
     health         = MAX_HEALTH;
     enemyMask      = 1 << LayerMask.NameToLayer("Enemy");
     areaCheck      = new Vector2(.1f, HEIGHT - .1f);
     facingRight    = true;
     attackable     = true;
     active         = true;
 }