Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        horiz = Input.GetAxisRaw("Horizontal");
        if (rb.velocity.x != 0 && on_ground && horiz != 0)
        {
            count++;
        }
        if (horiz != 0 && rb.velocity.magnitude < max_vel)
        {
            rb.velocity += new Vector2(horiz * speed * Time.deltaTime, 0);
        }
        else if (horiz == 0)
        {
            rb.velocity -= new Vector2(rb.velocity.x / decel, 0);
        }
        if (horiz < 0 && is_right == true && can_attack)
        {
            is_right = false;
            ac.rotate_sword();
        }
        else if (horiz > 0 && is_right == false && can_attack)
        {
            is_right = true;
            ac.rotate_sword();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (touching_ground())
            {
                rb.AddForce(new Vector2(0, jump_power), ForceMode2D.Impulse);
                need_land = true;
            }
        }

        if (Input.GetKeyDown(KeyCode.Mouse0) && can_attack)
        {
            ac.attack();
        }

        if (count >= 24)
        {
            step.Step();
            count = 0;
        }
    }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        horiz = Find_Player();
        if (rb.velocity.x != 0 && on_ground)
        {
            count++;
        }
        if (horiz != 0 && rb.velocity.magnitude < max_vel)
        {
            rb.velocity += new Vector2(horiz * speed * Time.deltaTime, 0);
        }
        else if (horiz == 0)
        {
            rb.velocity -= new Vector2(rb.velocity.x / decel, 0);
        }
        if (rb.velocity.x < 0 && is_right == true)
        {
            is_right = false;
            ac.rotate_sword();
        }
        else if (rb.velocity.x > 0 && is_right == false)
        {
            is_right = true;
            ac.rotate_sword();
        }


        if (count >= 24)
        {
            step.Step();
            count = 0;
        }

        if (Mathf.Abs(transform.position.magnitude - player.transform.position.magnitude) < 1f)
        {
            ac.attack();
        }
    }