I made Character Controller with AddForce:
void Update()
{
if (Input.GetKey(KeyCode.D)) {
GetComponent<SpriteRenderer>().flipX = false;
GetComponent<Rigidbody2D>().AddForce(new Vector2(1, 0), ForceMode2D.Force);
}
else if (Input.GetKey(KeyCode.A)) {
GetComponent<SpriteRenderer>().flipX = true;
GetComponent<Rigidbody2D>().AddForce(new Vector2(-1, 0), ForceMode2D.Force);
}
else if (Input.GetKeyDown(KeyCode.Space) && !inAir) {
inAir = true;
GetComponent<Rigidbody2D>().AddForce(new Vector2(0, 10), ForceMode2D.Impulse);
}
if (Input.GetKeyDown(KeyCode.R)) {
inAir = false;
transform.position = new Vector3((float)-5.47, (float)-1.07, 0);
}
}
Force mode doesnt work after building the game, jump work fine. But both works fine in Unity Play mode What wrong?