2075 / Unity / 2D / Гравець / Flappy Bird
FlappyBird2D | MoveGenerator2D |
- Rigitbody2D: Freez Rotation z
Варіант 1 public float speed = 0.1f; public float jumpForce = 10.0f; Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { if (Input.GetButton("Jump")) { //rb.velocity = Vector3.zero; rb.AddForce(new Vector2(0, jumpForce)); } } void FixedUpdate() { transform.position += new Vector3(speed, 0f, 0f); }
Варіант 2 Rigidbody2D rb; public float speed; public float flapHeight; void Start () { rb = GetComponent<Rigidbody2D>(); } void Update () { rb.velocity = new Vector2(speed, rb.velocity.y); if (Input.GetButton("Jump")) { rb.velocity = new Vector2(rb.velocity.x, flapHeight); } }