Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Complete Beginner Trying to Make a Flappy Bird Game But...

Discussion in 'Getting Started' started by minfabian, Jan 17, 2023.

Thread Status:
Not open for further replies.
  1. minfabian

    minfabian

    Joined:
    Jan 17, 2023
    Posts:
    2
    Hello everyone,

    I'm a novice in Unity and code but trying to learn them while following a tutorial (The Unity Tutorial For Complete Beginners by Game Maker's Toolkit) where we are building a similar game to Flappy Bird.

    I've basically followed the steps, trying to understand the code but something's off. In the PipeSpawnScript something is off because all my pipes spawn inside one another.

    I will paste the code below, maybe someone could give me some guidance.
    Thanks!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PipeSpawnScript : MonoBehaviour
    6. {
    7.     public GameObject pipe;
    8.     public float spawnRate = 2;
    9.     private float timer = 0;
    10.     public float heightOffset = 10;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         spawnPipe();
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         if (timer < spawnRate)
    22.         {
    23.             timer = timer + Time.deltaTime;
    24.         }
    25.         else
    26.         {
    27.             spawnPipe();
    28.             timer = 0;
    29.         }
    30.  
    31.     }
    32.  
    33.     void spawnPipe()
    34.     {
    35.         float lowestPoint = transform.position.y - heightOffset;
    36.         float highestPoint = transform.position.y + heightOffset;
    37.  
    38.         Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
    39.     }
    40. }
     
  2. minfabian

    minfabian

    Joined:
    Jan 17, 2023
    Posts:
    2
    Okai.. weird

    I've just opened the PipeMoveScript and changed the speed value ... and now it works. :
     
    jstaines91 likes this.
  3. RichAllen2023

    RichAllen2023

    Joined:
    Jul 19, 2016
    Posts:
    1,026
    Well done for getting it to work, on your own :)
     
Thread Status:
Not open for further replies.