Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question Help me Flappy Bird Fans

Discussion in 'Scripting' started by silversaintsco, Jun 9, 2020.

  1. silversaintsco

    silversaintsco

    Joined:
    Jun 9, 2020
    Posts:
    3
    So im currently making a flappy bird game (for practice) and im having a little bit of an issue when i try to use velocity and stuff it wont show when i put the script on my character... please help me i want to learn

    This is what i want to do:



    this is my code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Character : MonoBehaviour {
    6.  
    7.     public Rigidbody2D rb;
    8. public float moveSpeed;
    9. public float flapHeight;
    10. public GameObject pipe_up;
    11. public GameObject pipe_down
    12.  
    13.    
    14.     void Start() {
    15.         rb = GetComponent<Rigidbody2D>();
    16.  
    17.  
    18.     }
    19.  
    20.    
    21.     void Update() {
    22.  
    23.         rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
    24.  
    25.         if (Input.GetMouseButtonDown(0))
    26.         {
    27.             rb.velocity = new Vector2(rb.velocity.x, flapHeight);
    28.         }
    29.  
    30.         if (transform.position.y) > 18 || transform.position.y < -19)
    31.        {
    32.             Death();
    33.        }
    34.  
    35.      }
    36.  
    37.     public void Death()
    38.     {
    39.         rb.velocity = Vector3.zero;
    40.         transform.position = new Vector2(0, 0);
    41.  
    42.  
    43.     }
    44.