Spawning Objects in Unity [Using Instantiate]

Поделиться
HTML-код
  • Опубликовано: 23 янв 2025

Комментарии • 379

  • @pressstart6864
    @pressstart6864  6 лет назад +30

    Copy & paste source code: pressstart.vip/tutorials/2018/09/25/58/spawning-obstacles.html

    • @myworld7667
      @myworld7667 4 года назад

      i need some help, can you help me... i copy the code but i dont know how change rocks movement from below to up.... i try the code but when i play the scene the rocks its not found but it is work....

    • @myworld7667
      @myworld7667 4 года назад

      i dont know where is my fault

    • @moncicis
      @moncicis 4 года назад +1

      that code used in perspective camera...not orthographic

    • @leostudios5700
      @leostudios5700 4 года назад

      The code is not workkng for me and i dont know why it says i have have no where to put the asteroid prefab or the respawn time it wont pop up kn the knspector

    • @pegassus-oj1zj
      @pegassus-oj1zj 4 года назад

      @@myworld7667 did you change the axes

  • @Tanicorn
    @Tanicorn 4 года назад +116

    "Quarantines can look scary but they're actually quite simple"
    The World:"Sorry what I don't understand?"

    • @soaringsquid0.129
      @soaringsquid0.129 4 года назад +5

      TaniCorn I think you mean coroutines

    • @thenukdevendra1902
      @thenukdevendra1902 4 года назад +1

      Look where we are now and you might understand lol

    • @zombiepigmandude7759
      @zombiepigmandude7759 4 года назад +2

      @@soaringsquid0.129 r/woosh

    • @cryo7180
      @cryo7180 4 года назад +2

      YES THIS, i was like.... is it supposed to be Quarantine... or Co - ROUTINE?!?!?!

    • @Gir_0
      @Gir_0 4 года назад

      IKR

  • @thenukdevendra1902
    @thenukdevendra1902 4 года назад +6

    1 of the only youtubers that actually explain in a way that even beginners can understand.

  • @Berniebud
    @Berniebud 6 лет назад +4

    9:35 OK FINALLY I was so confused because nowhere could I find where you actually reference the prefab itself god bless you

    • @davidtelloph
      @davidtelloph 4 года назад

      I dont have it and i already save the script, someone help?

  • @inigoarribillaga1183
    @inigoarribillaga1183 6 лет назад +68

    I see you haven't uploaded in a while. I wanted to let you know that all your videos have been very helpful to me and that I would like to see more content from you, if you can of course. Thanks for your service.

    • @pressstart6864
      @pressstart6864  6 лет назад +22

      Thanks bud! Don't worry I will be posting videos again soon. I needed to take some time off to build out a website and do some rebranding, and things like that. Hopefully by the end of this month I'll have a consistent posting schedule. Cheers!

    • @JakeSimmer
      @JakeSimmer Год назад

      Hi, I just found this channel and it's very clear to follow along, but also I've been watching alot of vids these days because of the steep learning curve... It starts to make a little more sence now...

  • @figgi_myestrio5092
    @figgi_myestrio5092 4 года назад +1

    I was searching for a solution for months and you explained it very finely.
    I liked and subscribed. :)
    Thank you. :)

  • @knightmarerip711
    @knightmarerip711 5 лет назад +7

    This is pretty neat and so simple. Very well explained! Excellent job!

  • @Thornlock
    @Thornlock 6 лет назад +5

    Great tutorials dude! Really hope you keep making these

    • @pressstart6864
      @pressstart6864  6 лет назад +4

      Thornlock thank you for the support. I’ll be taking off the month of December to work on another project but after that I’ll be posting at least once a week.

  • @julian_phoenix
    @julian_phoenix 4 года назад

    Bro, you're AWESOME. The only one in the whole World Whide Web who helped me out with exactly what I needed. Muchas gracias

  • @OliverJ440
    @OliverJ440 2 года назад

    Thx. This is mega helpful. I have been looking for this for a long time, now i found it!

  • @daichi_devs
    @daichi_devs 5 лет назад

    Hey man just wanted to say this was such a great help for me. You are awesome, keep it up!!

  • @quessure6293
    @quessure6293 4 года назад +30

    my object disappears on play. help

    • @1984ordep
      @1984ordep 2 года назад +2

      from the amount of LIKES it seems a lot of us have the same issue my self included. they flash quickly at the left side of the screen...

    • @primebalpreet5214
      @primebalpreet5214 2 года назад +1

      Maybe because of camera. Go to camera and change projection to Perscpective

    • @apinoita
      @apinoita 2 года назад

      @@primebalpreet5214 kiitos! (Thanks in finnish)

    • @darkknight2825
      @darkknight2825 2 года назад

      @@primebalpreet5214 thanks that works

    • @eduardo-zf2eo
      @eduardo-zf2eo Год назад

      @@primebalpreet5214 thx 🙏🏻

  • @SebastianDrews
    @SebastianDrews 5 лет назад +6

    Thanks man, just what I needed, will definitely use this knowledge for my project! :)

  • @psychospoiler
    @psychospoiler 5 лет назад +1

    This really helped me for my mini platform game assignment. Thank you!

  • @_pratyush
    @_pratyush 4 года назад +2

    Hey can anyone help me!
    My Game Object (Asteroid) is spawning way behind the camera view and gets destroyed.

  • @tomsted2902
    @tomsted2902 4 года назад +4

    Simply amazing. It's hard to find such a good quality tutorials like yours. Thanks a lot :)

    • @huzaifa8530
      @huzaifa8530 2 года назад

      He does not even damn!! Explains it Whats the thanks for

  • @mrlloydval2887
    @mrlloydval2887 5 лет назад +5

    i'm very new to unity, c#, making games and stuff. i don't have a deep understanding of most of this, but i noticed that the code you used here 4:29 "if(transform.position.x < screenBounds.x)", the < screenBounds.x part only seems to work when the camera projection is set to perspective.
    i've been using the orthographic camera projection because i was told that it's better for 2d games. if not would you mind explaining the difference? also do you plan on making a tutorial like this for an orthographic camera projection?

    • @pressstart6864
      @pressstart6864  5 лет назад +3

      The simple answer is perspective camera inverts the screenBounds value. So if you’re dealing with orthographic either multiply it by -1 or flip the if statements. Hope that helps

    • @mrlloydval2887
      @mrlloydval2887 5 лет назад +1

      @@pressstart6864
      thanks a lot for the information. i was able to get it to work with orthographic projection when i multiplied it by -1. i wasn't able to figure out how to get it to work by flipping the if statements though.

  • @vletsy
    @vletsy 5 лет назад +3

    Idk if your still respone but i have an question how to let the astriod fly down unstat of to the left

    • @pressstart6864
      @pressstart6864  5 лет назад

      Change the velocity to be on the Y axis

    • @anttiuusoksa549
      @anttiuusoksa549 5 лет назад

      @@pressstart6864 I am beginner of coding and my question is what I have to do to change the velocity to y axis. Hope you respone quickly

  • @erika2_2
    @erika2_2 4 года назад

    At 9:01 you said we could use a boolean that changes to true when the game is ready to start. How do I know when the game is ready to start? Because my game has a title and doesn't start right away, so i dont want the enemies to spawn before the game actually begins, but how can I do this?

  • @randomdev9976
    @randomdev9976 2 года назад +1

    dude you give me a jumpscare with that intro

  • @gregbriggs9225
    @gregbriggs9225 4 года назад +2

    So I believe as TaniCorn is pointing out, it should be pronounced co-routine, not Quarantine, although that's all been on our mind recently.
    EDIT
    Thanks for the great vid!

  • @Nerodess
    @Nerodess 4 года назад +3

    I followed your tutorial step by step. My script is identical to yours (have checked for 1h). But nothing seems to spawn. If I put an asteroid manually in, it does, what it should. but if I remove it and try using the prefab, it just doesn't spawn anything... pls help! (using the 2019 Version of unity)

    • @Dorodigital
      @Dorodigital Год назад +1

      yeh this is Bull! same thing happened to me no spawn

  • @DH-yb7fz
    @DH-yb7fz 4 года назад

    This actually worked for me! Thank you so much!!

  • @boniebob7200
    @boniebob7200 4 года назад +2

    When the camera projection is "perspective" the objects despawn normally, but when I set it to "orthographic" the objects spawn faster than they can despawn. Can anyone help, plaease?

  • @cgnotavailable
    @cgnotavailable 2 года назад +1

    What is the best resolution to an image to get it to

  • @MyThatsCrazy
    @MyThatsCrazy 5 лет назад +3

    i'm getting an error saying object referance is not set tto an instance of an object for this line of the code and its saying it for both scripts
    screenBounds = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, Camera.main.transform.position.z));
    any one have any suggestions on how to fix this?

    • @pressstart6864
      @pressstart6864  5 лет назад

      You need to set your main camera. Basically it's just a tag in the inspector. Set it to main and the code will work

  • @flamed4967
    @flamed4967 4 года назад +2

    My enemies are just spawning off to the side not even in game view :/ Any help?

  • @jadthoumy8561
    @jadthoumy8561 4 года назад +1

    hey mate, I'm having issues I've copied and pasted the same code for destroying the asteroids but they are being destroyed at runtime, any suggestions? Please respond me fast, I have an assignment to finish

  • @milo1269
    @milo1269 4 года назад +1

    I was wondering how you would make the Asteroids spawn downwards vertically, instead of horizontally. Thanks.

    • @milo1269
      @milo1269 4 года назад +1

      @KeepenCool Thanks! I managed to get it working!

    • @Prankbros299
      @Prankbros299 2 года назад +1

      @@milo1269 pls can u explain it to me how

  • @DJ-xx7qi
    @DJ-xx7qi 5 лет назад

    Is there a way to cycle through several asteroid prefabs in the spawn?

  • @gamesentertainments9930
    @gamesentertainments9930 3 года назад

    Can you tell me that how to use two prefabs to spawn.

  • @krishshah1806
    @krishshah1806 4 года назад +2

    For some reason, whenever I run my game, the asteroid disappears right way. Anyway I can fix this issue?

    • @lordcatington8188
      @lordcatington8188 4 года назад +4

      Idk if you still need this but change the camera to perspective (I had the same problem, this just doesn't work with orthographic that's all)

    • @Iontaraxia
      @Iontaraxia 4 года назад +2

      @@lordcatington8188 had same problem as his, thanks m8

    • @ethannewman963
      @ethannewman963 4 года назад

      @@lordcatington8188 Thank you so much you really helped me

    • @AaronDerpy
      @AaronDerpy 4 года назад

      @@lordcatington8188 Thank you very much!!

  • @markrepac9739
    @markrepac9739 4 года назад

    i need help because when my mane object is destroyed the clones are not spawning any more
    can someone tell me whats wrong

  • @mrhopeis6134
    @mrhopeis6134 2 года назад

    This helped so much in my game. Thank you

  • @aabaloch1801
    @aabaloch1801 3 года назад

    My Object Doesn't spawn any help please

  • @ecapgaming2931
    @ecapgaming2931 4 года назад

    It is great but what is corontine it says it doesn’t exist plz help when I delete it they don’t spawn 😢😢😢

  • @ahnungsloser4157
    @ahnungsloser4157 5 лет назад

    Hey! There is a bug .... My Obstacles dont despawn and are spawning only there where the camera startet but when the camera is in another position the Obstacles are still spawning there where the camera was at the beginning... Can anyone help?

  • @Sheffy_TF2
    @Sheffy_TF2 3 года назад

    when i use the Removing objects from the scene once they leave the screen script its just destroys the objects even if its seen by the camera

  • @Prankbros299
    @Prankbros299 3 года назад

    The asteroids doesnt start at the right side. It starts in the middle. Does anyone know what to do?

  • @BhargavMarpu
    @BhargavMarpu 4 года назад

    Thanq for the clear explanation.. It helped a lot :)

  • @Algunalien_00
    @Algunalien_00 5 лет назад +1

    Nice tutorial, very clear!

  • @AhmedAymanM
    @AhmedAymanM Год назад +1

    The screenboundaries code is correct, it should be something like this:
    if (transform.position.x + screenBounds.x < 0)

  • @mcbobber6913
    @mcbobber6913 3 года назад +1

    It doesn’t say any errors but it won’t spawn the asteroids

  • @AykutKaramanTV
    @AykutKaramanTV 4 года назад +1

    ORTHOGRAPHIC CAMERAS objects do not come out.
    How can we find a solution?

    • @AykutKaramanTV
      @AykutKaramanTV 4 года назад

      Objects are outside the screen.
      How can we put the screen inside. ?

  • @ivanpopovic9501
    @ivanpopovic9501 4 года назад +1

    hey, i have problem, when my first prefab gets destroyed, unity stops cloning it since it's destroyed
    any solution for this?

    • @lassespfs4570
      @lassespfs4570 4 года назад

      Dont have your prefab in your scene just add it to the camera

  • @Christ0hell
    @Christ0hell 2 года назад

    Not sure what i have done wrong here but the object i want to be deleted off screen immediately deletes itself. Checked code over and over not sure what i am missing.

    • @cookieceleste
      @cookieceleste 2 года назад +1

      In the Update method, try multiplying your "screenBounds.x" by -1, like this -> if (transform.position.x < screenBounds.x * -1). Looks like the problem is he was using his camera on "Perspective" mode, when most of the time we use it on "Orthographic" mode for 2D projects, and that reverses some things.

  • @revel6016
    @revel6016 4 года назад +1

    How do I spawn it in just a staight line?

  • @kubakakauko
    @kubakakauko 6 лет назад +3

    I will leave this comment just for stats. i would love for your channel to get big

  • @siggetiger5239
    @siggetiger5239 2 года назад

    does somebody knows how to the same thing but the asteriods goes down not sideways

  • @sharaharan3483
    @sharaharan3483 2 года назад

    Hi , I tried it for Y axis, but the "DEPLOYASTEROID.CS" did not work for me. I tried changing the x axis to y axis, but the spawning didn't work. Pls help me. Thank you.

  • @謝宗佑-u1m
    @謝宗佑-u1m 5 лет назад +2

    Rocks stop spawning after one of them being deleted, how can I keep them spawning?

    • @pressstart6864
      @pressstart6864  5 лет назад +2

      You're probably deleting the object that spawns the obstacles. Try deleting the obstacles individually instead.

    • @謝宗佑-u1m
      @謝宗佑-u1m 5 лет назад +2

      @@pressstart6864 I found where the problem was, I forgot to delete the prefab in the scene before launching the game LOL

    • @Changelllelle
      @Changelllelle 5 лет назад +1

      Did you create a folder in assets called prefabs and added the rock in there? Then assign the rock from the prefab folder to the script that deploys the rocks, located in the main camera.

    • @nosegoatpolo5883
      @nosegoatpolo5883 5 лет назад +1

      How did you solve the problem?

    • @Abraham-om5ib
      @Abraham-om5ib 4 года назад

      @@Changelllelle wow thank you that was it :)

  • @josedron5207
    @josedron5207 2 года назад

    Brilliant tutorial, thank you.

  • @RecréerMarioEtZelda
    @RecréerMarioEtZelda 3 года назад

    hello from french,
    thank you for tuto, you help me ^^
    a good day.

  • @caseymckinney8377
    @caseymckinney8377 5 лет назад +1

    Also is there anyway to code it so instead, it seems like the enemies are 'dropping' from the top of the screen to the bottom?

    • @pressstart6864
      @pressstart6864  5 лет назад

      Yes just reverse the code to work for the Y axis:
      a.transform.position = new Vector2(Random.Range(-screenBounds.x, screenBounds.x), screenBounds.y * 2);
      Then modify the velocity also, or just add gravity.

    • @caseymckinney8377
      @caseymckinney8377 5 лет назад +1

      @@pressstart6864 Amazing; thank you so much! Currently working on a game for my university assignment, and your tutorials are a HUGE help!

  • @elotusa
    @elotusa 3 года назад

    My unity doesnt allow me to add onto my deloyasteroid script qwq idk how to make it work and its the same code used here

  • @lildgamedev6885
    @lildgamedev6885 2 года назад

    Hey this is great thanks! my question is I wanted to add a different object to be spawned so I made a new coroutine, but for some reason that one never spawns its object. Is the first coroutine interfering?

  • @gabrielbrazeau835
    @gabrielbrazeau835 3 года назад +1

    Super video!! Only thing is that you've could use the asteroid width instead of the (* 2/-2), but for the rest great job !!

  • @myworld7667
    @myworld7667 4 года назад

    thankyou very much but how i make the rocks move from below to up?????

  • @amor6611
    @amor6611 5 лет назад +1

    I have a small question, I'm shooting bullets, although it seems I'm creating multiple bullet game objects and I only want to fire one of them when the space key is pressed, how do we limit the rate of a prefab?

  • @deraminator945
    @deraminator945 3 года назад +1

    Is there anyone who did the same but in 3D? I tried but that didn't went well

  • @charlado8597
    @charlado8597 Год назад

    my game stop because the original asteroid that i put in the the deploy asteroid is missng

  • @mando7176
    @mando7176 5 лет назад +1

    I encountered a problem here. my clone of asteroid spawns for a few miliseconds, then after the main one get destroyed, no clone spawns..'

  • @szymonzielinski6327
    @szymonzielinski6327 3 года назад

    how to spawn an item only if previous one is already collected ? if is not then dont spawn

  • @SanityPotion776
    @SanityPotion776 5 лет назад +4

    Hey! great tutorial! Is there a way to increase the rate at which the astroids spawn over time? I would like them to spawn more frequently as the game progresses.

  • @thuzas11111
    @thuzas11111 4 года назад

    my prefabs are spawning only on one Y position whats the problem

  • @neozoid7009
    @neozoid7009 3 года назад

    Whats the difference between coroutine and invoke?

  • @noncraftx8790
    @noncraftx8790 4 года назад

    I made a game with Camera moves with Player please how script must looks to be good?

  • @dragonballz3686
    @dragonballz3686 3 года назад

    Bro, how to make a set of enemies coming in a straight line or forming sine wave or in a circle formation like space shooter games.

  • @Wolfnoir60
    @Wolfnoir60 2 года назад

    It freezes every time I click with deploy zombies scripts

  • @diothil2920
    @diothil2920 5 лет назад

    Thanks for helping me! I learned a lot!

  • @cm16533
    @cm16533 2 года назад

    Does anyone know why my object would be deleted upon entering the screen instead of leaving it? I have the exact code as copied in the video :(

    • @cookieceleste
      @cookieceleste 2 года назад

      In the Update method, try multiplying your "screenBounds.x" by -1, like this -> if (transform.position.x < screenBounds.x * -1). Looks like the problem is he was using his camera on "Perspective" mode, when most of the time we use it on "Orthographic" mode for 2D projects, and that reverses some things.

  • @d.a9346
    @d.a9346 3 года назад

    is there a way to make in go from top to bottom instead of right to left

    • @ASKAL_PT
      @ASKAL_PT 10 месяцев назад

      Replace every “x” with “y”

  • @TurbulentGamer
    @TurbulentGamer 6 лет назад +1

    my object disappears in the middle of the screen and I want it to be from top to bottom

    • @pressstart6864
      @pressstart6864  6 лет назад +4

      In asteroid.cs, change this line to move from top to bottom:
      rb.velocity = new Vector2(0, -speed);
      and in deployasteroid.cs change this line to have it appear above the camera:
      a.transform.position = new Vector2(Random.Range(-screenBounds.x, screenBounds.x), screenBounds.y * -2);

    • @DewiHermawaningsih
      @DewiHermawaningsih 5 лет назад

      @@pressstart6864 hey buddy, how to make more than 1 object to spawning? not only asteroid,, please help me

  • @hallowedheroin
    @hallowedheroin 4 года назад

    I have an issue with the code, the obstacle destroys itself immediately after the game starts. I even tried copying and pasting the code! help

    • @kevinanderson9458
      @kevinanderson9458 3 года назад

      did you figure this out? I am having the same issue.

    • @hallowedheroin
      @hallowedheroin 3 года назад

      @@kevinanderson9458 nah I just gave up after that

  • @abdullahamjad3612
    @abdullahamjad3612 6 лет назад +1

    sir How can i apply such CODE in an 3d runner game when camera is from behind

  • @allengullon624
    @allengullon624 5 лет назад

    Hello how to instantiate prefab to the main camera position?

  • @tuando8511
    @tuando8511 5 лет назад

    Hello, why do i have this error?
    MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.

    • @pressstart6864
      @pressstart6864  5 лет назад

      You probably put the code in the wrong place.

    • @charlado8597
      @charlado8597 Год назад

      @@pressstart6864 i put it in the camera

  • @davidregalado3037
    @davidregalado3037 3 года назад +1

    How can I make more obstacles spawn through the progress of the game? Also great tutorial.

  • @liamtinney5759
    @liamtinney5759 6 лет назад +2

    my script completely ignores what i typed and destroys the gameobject instantly

    • @ehawknut3797
      @ehawknut3797 6 лет назад

      Please help me. Mine does the exact same thing.

    • @PraveenKumar-pj9ls
      @PraveenKumar-pj9ls 6 лет назад +5

      @@ehawknut3797 me too faced the same problem. Screenbounds.x gives me positive value (don't know how), so i gave minus in front of screenbounds.x inside if condition and works fine now.

    • @CanisMajoris_star
      @CanisMajoris_star 5 лет назад

      ​@@PraveenKumar-pj9ls This worked for me. Thank you

    • @Rxbsi
      @Rxbsi 4 года назад

      Make - 25 instead of * 2

  • @jahmaijones6331
    @jahmaijones6331 6 лет назад +1

    If i were to do this for a top down shooter i should just replace the values with Z instead correct ? im trying to do this for a top down space shooter

    • @pressstart6864
      @pressstart6864  6 лет назад

      It's relative to your camera. You could just rotate your camera or yes change certain values. Not every project is going to be the same.

  • @loghanveilleux
    @loghanveilleux 2 года назад

    it fixed my problem that i was having with my spawn system thanks a lot😎😎😎😎😁😁😁😁😁😁😁😁

  • @mehva7382
    @mehva7382 2 года назад

    does this also work up and down? not just left to right

  • @Skildepadde
    @Skildepadde 5 лет назад

    Hey, can someone help me with a problem I am running into? So I am trying to make this script but instead of the asteroids going sideways I want them to go down so I did that but now the asteroids are going down on one line. In the "deployAsteroids" script I have tried to change "screenBounds.x * -2" to "screenBounds.y * -2" I have also tried to change the Random.Range screenBounds to x instead of y. Btw I am a beginner coder so I am sorry if it is something obvious.

  • @dankdat620
    @dankdat620 3 года назад

    My missile disappears instantly once I run the game, any ideas? :/

  • @BattlePlayer11
    @BattlePlayer11 4 года назад

    My asteroids fly on for quite awhile after leaving the screen before being destroyed. Does somebody know why that is?

  • @caseymckinney8377
    @caseymckinney8377 5 лет назад +2

    my enemies just seem to glitch off the other side of the screen, without appearing in the game view at all; any help

    • @pressstart6864
      @pressstart6864  5 лет назад +1

      Is your camera moving or is it static?

    • @caseymckinney8377
      @caseymckinney8377 5 лет назад +1

      @@pressstart6864 It appears static, but it turns out it's technically moving? I tried the code you suggested to someone having a similar issue and it resolved my problem :)

    • @juncooo7505
      @juncooo7505 5 лет назад +2

      @@pressstart6864 I have the same issue. My camera is moving

    • @JaquanGrand
      @JaquanGrand 4 года назад

      @@caseymckinney8377 what was the code you used to fix this issue

    • @rohitrana2312idk
      @rohitrana2312idk 4 года назад

      @@JaquanGrand I had the same problem, idk why.
      I destroyed the item with a timer, instead of screenbounds

  • @chetang7838
    @chetang7838 2 года назад

    Thank you very much it helped a lot in my project

  • @robby.108
    @robby.108 3 года назад

    Hey, I have a question. How can I rewrite this code to make the asteroids fall from top to bottom?

    • @Prankbros299
      @Prankbros299 2 года назад

      @Jurgen Thank You so much!

    • @Prankbros299
      @Prankbros299 2 года назад

      @Jurgen But in the code where it destroys it self when it touches the end, it instantly destroys it self when u press start

  • @VeryHappyCat
    @VeryHappyCat 2 года назад

    Can you make it so that the clones get slowly faster the longer you play?

  • @neozoid7009
    @neozoid7009 3 года назад

    Cool tutorial ,thanks 👍

  • @rojinx4162
    @rojinx4162 5 лет назад

    How do i delete the asteroid after it leaves the y axis? iv used the script: void Update()
    {
    if(transform.position.y < ScreenBounds.y * 2)
    {
    Destroy(this.gameObject);
    }
    }
    but it deletes itself at any point on the screen.

    • @rojinx4162
      @rojinx4162 5 лет назад +2

      Im using an orthographic camera if that helps

    • @pressstart6864
      @pressstart6864  5 лет назад

      If using orthographic camera use -screenBounds.y

    • @pressstart6864
      @pressstart6864  5 лет назад

      Or multiply by -1

  • @kuritsu6239
    @kuritsu6239 5 лет назад +3

    Just a great tutorial as always ! thanks
    Can you explain us how to create the space background ?

    • @pressstart6864
      @pressstart6864  5 лет назад +1

      I used a particle effect. For start size choose a value less than 0.1 and then under Renderer > Material choose "Sprites - Default". Then just rotate it 90 degrees.

    • @kuritsu6239
      @kuritsu6239 5 лет назад +2

      @@pressstart6864 Great ! It looks so awesome !

  • @kingmuzzy
    @kingmuzzy 5 лет назад

    My object will not delete when off the screen not sure why maybe there is a problem with the camera bounds , any suggestions? (I had to change the code to what you put in the comments, to make my prefab appear on the screen as it wasn't showing with your original code)

  • @gokcekapci
    @gokcekapci 2 года назад

    Maybe you won't answer but I still want to ask. You wrote the respawn time as "WaitForSeconds(RespawnTime), but I want it to create a new object for each disappearing object condition, not time. So the respawn condition is for another object to disappear. How can I do this? Thanks in advance for the information you will provide. I wish you good work.

  • @rojinx4162
    @rojinx4162 5 лет назад

    The line if(transform.position.x < screenBounds.x)
    {
    Destroy(this.gameObject);
    }
    seems to destroy my camera so i cant see anything happening in the game, how can i fix this?

    • @silver440
      @silver440 5 лет назад +1

      void Update () {
      if(transform.position.x < screenBounds.x * 2){
      Destroy(this.gameObject);
      }
      }
      thats what the source code said, i think you might have forgotten the * 2

    • @rojinx4162
      @rojinx4162 5 лет назад +1

      @@silver440 I think i had the script bound to my camera, so the camera would destroy itself lol, and ty for the reply btw

    • @silver440
      @silver440 5 лет назад +1

      Oh lol, I just realized that the * 2 was nothing more than padding, so it shouldn't have affected the camera. Nice job though and good luck 😃

  • @GhostStories605
    @GhostStories605 4 года назад

    void Update () {
    if(transform.position.x < screenBounds.x * 2){
    Destroy(this.gameObject);
    }
    }
    why these lines are not working

  • @mikemitchley384
    @mikemitchley384 3 года назад

    Hi, how do i change the amount of objects spawned at a time i want to increase it as the game continues?

  • @nabilbensafi
    @nabilbensafi 3 года назад +2

    Hi , I appreciate the video. Just a quick question : so I'm working on a simple 2D side scrolling runner, the idea is to deliver Pizza to randomly generated houses : green red and blue ( to add a bit of challenge ) , will the script you provided in this video work ? I've been trying for so long but I can't make the houses spawn after the player collides with them.
    Any help would be appreciated. Thanks.

  • @ugryksl
    @ugryksl 5 лет назад +1

    My camera moves top of screen. Objects create but dont destroy :(

    • @pressstart6864
      @pressstart6864  5 лет назад

      Not sure I understand. If your objects are moving vertically, just change this line:
      if(transform.position.y < -screenBounds.y * 2){
      Destroy(this.gameObject);
      }

  • @shmowp5379
    @shmowp5379 4 года назад

    my code says that Random is an ambiguous reference to unityEngine.Random and System. Random
    what do i do to fix this?
    if i add system.random my game says Random does not contain a definition for range