publicclassHereWeGoMove : MonoBehaviour
{
privateRigidbody2Drb;
publicfloatjumpSpeed = 1200f;
publicboolgrounded = false;
publicTransformgroundCheck;
publicfloatgroundRadius = 0.2f;
publicLayerMaskwhatIsGround;
publicfloatmoveDirection;
publicfloatmaxSpeed = 0.25f;
publicboolfacingRight = true;
publicbooldoubleJump = false;
publicboolcanDoubleJump;
intcount = 2;
voidAwake()
{
groundCheck = GameObject.Find(“Cube”).transform;
}
voidStart ()
{
rb = GetComponent();
}
voidFixedUpdate ()
{
if(grounded)
doubleJump = false;
if(moveDirection < 0.0f)
{
rb.transform.Translate(newVector3(0, 0, -(moveDirection * maxSpeed)));
}
elseif(moveDirection > 0.0f)
{
rb.transform.Translate(newVector3(0, 0, moveDirection * maxSpeed));
}
//rb.velocity = newVector2(moveDirection * maxSpeed, rb.velocity.y);
grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
if(count > 0)
{
if ((grounded || !doubleJump) && Input.GetButtonDown(“Jump”))
{
rb.AddForce(newVector2(0, jumpSpeed));
rb.gravityScale = 9.8f;
if(!doubleJump && !grounded)
doubleJump = true;
print ("count = " + count);
count --;
}
}
}
voidUpdate()
{
moveDirection = Input.GetAxis(“Horizontal”);
if(moveDirection > 0.0f && !facingRight)
{
Flip();
}
if(moveDirection < 0.0f && facingRight)
{
Flip();
}
}
voidFlip()
{
facingRight = !facingRight;
transform.Rotate(Vector3.up, 180.0f, Space.World);
}
}