Unity 2D Flappy Bird

Варіант 1

public float moveSpeed = 0.1f;
public float jumpForce = 200.0f;
Rigidbody2D rb;

void Start()
{
  rb = GetComponent<Rigidbody2D>();
}

void Update()
{
  if (Input.GetKeyDown(KeyCode.Space))
  {
    rb.AddForce(new Vector2(0, jumpForce));
  }
}

void FixedUpdate()
{
  transform.position += new Vector3(moveSpeed, 0f, 0f);
}






Варіант 2

Rigidbody2D rb;
public float moveSpeed;
public float flapHeight;

void Start () {
  rb = GetComponent<Rigidbody2D>();
}

void Update () {
  rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
  if (Input.GetMouseButtonDown(0))
  {
    rb.velocity = new Vector2(rb.velocity.x, flapHeight);
  }
}