Wall Jump and loops

Ok two questions,

Is there any while loops, or something similar, so i can do certain things while in a specific state? For example for the wall jump i want to say

//
while(touching wall)
{
Pause for a second then drift slowly down
}

otherwise gravity is normal
//

But anything I try the character will drift slowly down after touching the wall then moving to the side and not actually being on the wall.

Second question. If i want him to jump off the wall, if there a better way then changing the horizontal velocity? I only want him to move about 5-10 ‘units’ away from the way then hold normal horizontal velocity.

for your first question, you want to use a coroutine.

for your second question, you want to interpolate from one position to the other using Mathf.SmoothDamp.

  1. Either store your states in an Enum type variable or assign a toggle variable for each state.
  2. You can clamp the horizontal component of the velocity after a specified condition is fulfilled.

I suppose my greatest question is how does Mathf.SmoothDamp work? I looked it up but cant figure it out http://unity3d.com/support/documentation/ScriptReference/Mathf.SmoothDamp.html

@jlimbach i just used an if statement…` if (CheckIfOnWallToRight() == true)
{
// make you jump of the wall
if ((Input.GetButtonDown(“Jump”)) && (Input.GetButton(“d”)))
{
playerController.GetComponent().enabled = false;
rb.velocity = new Vector2(-5, 10);
wallJumpedFromRight = true;
}
// makes you wall slide
else if ((Input.GetKey(“d”)) && (wallJumpedFromRight == false))
{
rb.velocity = new Vector2(0, -1);
Debug.Log(wallJumpedFromRight);
}
}

    if (wallJumpedFromRight == true)
    {
        iR += 1;
    }
    if (iR >= 25)
    {
        iR = 0;
        wallJumpedFromRight = false;
        playerController.GetComponent<PlayerMovement>().enabled = true;
    }`

mathf.smoothdamp looks goood, but I cant seem to figure out how to make it work. Does that just keep returning a value that i set to his x position?