My pipe spawn script won't work!

Hello again…

I wanted to make a Flappy bird remake in Unity… But my pipe spawn script won’t work! Here’s the script :

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

public class pipespawner : MonoBehaviour
{
   
    public float maxTime = 1;
    private float timer 0;
    public GameObject pipe;
    public float height;
   
    // Use this for initialization
    void Start()
    {
        GameObject newpipe = Instantiate(pipe);
        newpipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
    }

    // Update is called once per frame
    void Update()
    {
        if(timer > maxTime)
        {
            GameObject newpipe = Instantiate(pipe);
            newpipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
            Destroy(newpipe, 15);
            timer = 0;
        }
       
        timer += Time.deltaTime;
       
    }
}

And here is the error :
6159763--673432--upload_2020-8-2_10-57-11.png
I suppose with the error, it expected somewhere an “,”?

Thanks

No, actually, but the rest of the message tells your exactly where something is missing. If you had read your script carefully you would have found out what was missing already.

Huh. But how can I read the error thing so I can see where it is?

I’m only a beginner :smile:

Hello My friend this is the code you asked for and I am your fbi agent

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

public class deletethis : MonoBehaviour
{
    //This is the object which you want to spawn ^_^
    public GameObject pipe; // As you said
   // You have to Initialize this in the Inspector
   

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

    // Update is called once per frame
    void Update()
    {
        //This is the functin which spawn things

        //  This is the object to spawn || This is the location to spawn || And this is the roation for the spawned object 
        //In the below Function
        Instantiate(pipe, new Vector3(0f, 0f, 0f), Quaternion.identity);
    }
}
1 Like

The error message says “pipespawner.cs(9,25)” which means line 9, character 25 of your pipespawner script. Something is missing there and it’s not a “,”; you can easily figure out what it is if you compare this line with the other of the same kind you already wrote.

If you are a beginner, you need to learn how to write scripts, how to keep them clean and organized and about naming conventions.

The following course is for you, and for everyone trying to do something with Unity, and it’s free: https://learn.unity.com/course/unity-game-dev-course-programming-part-1

1 Like

Thanks!

Um FBI this code does not work it spawns infinite pipe at the smae time and it spawn at the same location as the bird is…

I got to the line and the character but idk what is wrong with it…



I tried using “f” after the numbers but doesnt work either!

Characters numbering begins with the first character of the line, even if it’s a blank space. This puts you before 0 and after reading the line before, you would have noticed that what was missing is “=”.

Believe me, take some time and learn. :slight_smile:

OOOOOooooooh I’m really stupid… Thank you!

Now there is no more errors!

You are not stupid, you just need to pay more attention. Writing code is very demanding. :slight_smile: