Example #1
0
 public void Move()
 {
     if (!Attack)
     {
         if ((GetDirection().x > 0 && transform.position.x < rightEdge.position.x) ||
             (GetDirection().x < 0 && transform.position.x > leftEdge.position.x))
         {
             MyAnim.SetFloat("speed", 1);
             transform.Translate(GetDirection() * (movementSpeed * Time.deltaTime));
         }
         else if (currentState is PatrolState)
         {
             ChangeDirection();
         }
     }
 }
Example #2
0
    private void HandleMovement(float horizontal)
    {
        if (myRigid.velocity.y < 0)
        {
            MyAnim.SetBool("land", true);
        }

        if (!Attack && !Roll)
        {
            myRigid.velocity = new Vector2(horizontal * movementSpeed, myRigid.velocity.y);
        }


        if (Jump && myRigid.velocity.y == 0)
        {
            myRigid.AddForce(new Vector2(0, jumpForce));
        }

        MyAnim.SetFloat("speed", Mathf.Abs(horizontal));
    }