So i use unity and i want my object to take height for as long as the player presses space
But for now he simply jumps and you gotta spam space for it to fly away
Could someone help me ?
private Rigidbody2D rb;
public float Speed;
private bool spacePressed;
public float jetForce;
pivate void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
spacePressed = true;
}
else
{
spacePressed = false;
}
Move();
Jet();
}
private void Move()
{
float x = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(Speed * x, rb.velocity.y);
}
private void Jet()
{
while (spacePressed == true)
{
rb.velocity = new Vector2(rb.velocity.x, jetForce);
}
}