Is there anything wrong with this flappy bird code?

Joined
Apr 16, 2023
Messages
1
Reaction score
0
I'm not sure if this is correct but this is the script for a flappy bird pipe spawner can anyone see any missing commas.
{
spawnknife();
}

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

}

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

Instantiate(Knife, new Vector3(transform.position.x, Random.Range(lowestPoint, highestPoint), 1), transform.rotation);
}
}
 
Joined
Mar 31, 2023
Messages
95
Reaction score
8
The code appears to be intended to generate knives that are instantiated and thrown into the game. However, it lacks some details such as setting variables, choosing parameters, and initializing objects. Here's a full version of the code you can use:

C++:
using UnityEngine;

public class KnifeSpawner : MonoBehaviour
{
    public GameObject Knife;
    public float spawnRate = 2f;
    public float heightOffset = 1f;

    private float timer = 0f;

  
    void Start()
    {
        spawnknife();
    }

    void Update()
    {
        if (timer < spawnRate)
        {
            timer = timer + Time.deltaTime;
        }
        else
        {
            spawnknife();
            timer = 0;
        }
    }

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top