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

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!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PipeSpawnScript : MonoBehaviour
{
    public GameObject pipe;
    public float spawnRate = 2;
    private float timer = 0;
    public float heightOffset = 10;

    // Start is called before the first frame update
    void Start()
    {
        spawnPipe();
    }

    // Update is called once per frame
    void Update()
    {
        if (timer < spawnRate)
        {
            timer = timer + Time.deltaTime;
        }
        else
        {
            spawnPipe();
            timer = 0;
        }

    }

    void spawnPipe()
    {
        float lowestPoint = transform.position.y - heightOffset;
        float highestPoint = transform.position.y + heightOffset;

        Instantiate(pipe, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 0), transform.rotation);
    }
}

Okai… weird

I’ve just opened the PipeMoveScript and changed the speed value … and now it works. :

1 Like

Well done for getting it to work, on your own :slight_smile: