Beispiel #1
0
    public void Moving()
    {
        Vector2 position_player = player.transform.position;
        Vector2 position_enemy  = this.transform.position;
        float   distance        = position_enemy.x - position_player.x;

        right = position_enemy.x < position_player.x ? 1 : -1;
        if (Math.Abs(distance) < 1)
        {
            horizontalMove = right * 0.001f;
            if (!crouch && !jump && !attack && UnityEngine.Random.Range(0f, 1f) < 0.1f && character.SetAttack(2))
            {
                animator.SetFloat("Move_n", .5f);
                animator.SetTrigger("Attack");
                attack = true;
            }
            if (!crouch && !attack && character.SetAttack(3))
            {
                animator.SetFloat("Move_n", .9f);
                animator.SetTrigger("Attack");
                attack = true;
            }
            else if (!jump && !crouch && !attack && character.SetAttack(1))
            {
                animator.SetFloat("Move_n", .2f);
                animator.SetTrigger("Attack");
                attack = true;
            }
        }
        else
        {
            horizontalMove = right * runSpeed;
        }
        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
    }
    // Update is called once per frame
    public virtual void Update()
    {
        //horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
        horizontalMove = joystick.Horizontal * runSpeed;
        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));

        if (joystick.Vertical > 0.5) //Input.GetButtonDown("Jump")
        {
            jump = true;
            animator.SetBool("IsJumping", true);
        }

        if (joystick.Vertical < -0.5)   // Input.GetButtonDown("Crouch")
        {
            crouch = true;
        }
        else // if (Input.GetButtonUp("Crouch"))
        {
            crouch = false;
        }

        if (move1.Pressed) //Input.GetButtonDown("Fire1")
        {
            if (!attack && !crouch && character.SetAttack(1))
            {
                animator.SetFloat("Move_n", .2f);
                animator.SetTrigger("Attack");
                attack = true;
            }
        }
        if (move2.Pressed)
        {
            if (!attack && !crouch && character.SetAttack(2))
            {
                animator.SetFloat("Move_n", .5f);
                animator.SetTrigger("Attack");
                attack = true;
            }
        }
        if (finalMove.Pressed)
        {
            if (!attack && !crouch && character.SetAttack(3))
            {
                animator.SetFloat("Move_n", .9f);
                animator.SetTrigger("Attack");
                attack = true;
            }
        }
    }