Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

My pipe spawn script won't work!

Discussion in '2D' started by Tassilo593, Aug 2, 2020.

  1. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    Hello again...

    I wanted to make a Flappy bird remake in Unity... But my pipe spawn script won't work! Here's the script :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class pipespawner : MonoBehaviour
    6. {
    7.    
    8.     public float maxTime = 1;
    9.     private float timer 0;
    10.     public GameObject pipe;
    11.     public float height;
    12.    
    13.     // Use this for initialization
    14.     void Start()
    15.     {
    16.         GameObject newpipe = Instantiate(pipe);
    17.         newpipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
    18.     }
    19.  
    20.     // Update is called once per frame
    21.     void Update()
    22.     {
    23.         if(timer > maxTime)
    24.         {
    25.             GameObject newpipe = Instantiate(pipe);
    26.             newpipe.transform.position = transform.position + new Vector3(0, Random.Range(-height, height), 0);
    27.             Destroy(newpipe, 15);
    28.             timer = 0;
    29.         }
    30.        
    31.         timer += Time.deltaTime;
    32.        
    33.     }
    34. }
    And here is the error :
    upload_2020-8-2_10-57-11.png
    I suppose with the error, it expected somewhere an ","?

    Thanks
     
  2. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    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.
     
  3. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    Huh. But how can I read the error thing so I can see where it is?
     
  4. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    I'm only a beginner :D
     
  5. Rahulbagdi

    Rahulbagdi

    Joined:
    May 9, 2020
    Posts:
    2
    Hello My friend this is the code you asked for and I am your fbi agent
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class deletethis : MonoBehaviour
    6. {
    7.     //This is the object which you want to spawn ^_^
    8.     public GameObject pipe; // As you said
    9.    // You have to Initialize this in the Inspector
    10.    
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.        
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         //This is the functin which spawn things
    22.  
    23.         //  This is the object to spawn || This is the location to spawn || And this is the roation for the spawned object
    24.         //In the below Function
    25.         Instantiate(pipe, new Vector3(0f, 0f, 0f), Quaternion.identity);
    26.     }
    27. }
    28.  
     
    Tassilo593 likes this.
  6. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    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
     
    Last edited: Aug 2, 2020
    Tassilo593 likes this.
  7. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    Thanks!
     
  8. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    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...
     
  9. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    I got to the line and the character but idk what is wrong with it...
    upload_2020-8-2_12-46-58.png
    upload_2020-8-2_12-45-36.png
    I tried using "f" after the numbers but doesnt work either!
     
    Last edited: Aug 2, 2020
  10. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    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. :)
     
  11. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    OOOOOooooooh I'm really stupid... Thank you!
     
  12. Tassilo593

    Tassilo593

    Joined:
    May 6, 2020
    Posts:
    45
    Now there is no more errors!
     
  13. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    You are not stupid, you just need to pay more attention. Writing code is very demanding. :)