PlayerControl.Move C# (CSharp) Method

Move() public method

public Move ( float h ) : void
h float
return void
    void Move(float h)
    {
        //prevent player from moving when hidden
        if (!hide)
        {
            // Set movement and normalize in terms of time passed from previous frame
            // (Assuming we will be frame rate dependent)
            movement.x = h;
            movement *= Time.deltaTime;

            // apply movement to player
            transform.Translate(movement);
            if (movement.x != 0)
            {
                anim.SetBool("Walking", true);
            }
            else
            {
                anim.SetBool("Walking", false);
            }
            //this checks which direction the player is moving and flips the player based upon that
            if (movement.x > 0 && facingRight == false)
            {
                FlipPlayer();
            }
            if (movement.x < 0 && facingRight == true)
            {
                FlipPlayer();
            }

        }
    }

Usage Example

Ejemplo n.º 1
0
 void Update()
 {
     if (Input.anyKey)
     {
         if (Input.GetKey(keys[(int)Dir.up]))
         {
             anotherScript.Move((int)Dir.up);
         }
         if (Input.GetKey(keys[(int)Dir.down]))
         {
             anotherScript.Move((int)Dir.down);
         }
         if (Input.GetKey(keys[(int)Dir.left]))
         {
             anotherScript.Move((int)Dir.left);
         }
         if (Input.GetKey(keys[(int)Dir.right]))
         {
             anotherScript.Move((int)Dir.right);
         }
     }
     else
     {
         anotherScript.Move((int)Dir.idle);
     }
 }
All Usage Examples Of PlayerControl::Move