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. Dismiss Notice

Showing and then deleting game objects after a delay?

Discussion in 'Scripting' started by Oritzia, Apr 5, 2021.

  1. Oritzia

    Oritzia

    Joined:
    Feb 2, 2021
    Posts:
    2
    So I'm creating a game for a final project in my program, we're nearing the end and we just realized we are going to need a tutorial to explain to players how to play the game. Our game is played entirely through the UI, and initially we were going to create a video, edit and use that as the tutorial in the game or take a more interactive route. Due to time constraints we're thinking our best bet is going to be a still image of our UI elements, with textboxes (Just text inside an empty game object with a background) that appear, wait about 8 seconds and then disappear and the next one appears.
    We're having a difficult time conceptualizing how to accomplish this, I believe our best bet with this is going to be to have an array of game objects that we iterate through, showing the first then after 8 seconds, destroy it and reveal the next for 8 seconds and then destroy and so on. Just looking for some insight on how we might be able to do this with a script. I feel like this is super easy and staring me in the face but I'm just having a difficult time conceptualizing it.
     
    jasonasaad2 likes this.
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    You could also consider letting the user advance on their own with a next button. Then it doesn't matter how long it takes them, they can read through at their own pace.
     
  4. Oritzia

    Oritzia

    Joined:
    Feb 2, 2021
    Posts:
    2
    Ahh yes, I think I'll be using a coroutine, it's an area I'm familiar with so this should be simple enough to do! Thanks again for the help! (Also thank you for bringing my attention to Timelines, I'll have to explore this feature!)
    Yeah, I think what I'm going to do is use a button on each game object and using a coroutine remove them as the button is clicked!
     
  5. jasonasaad2

    jasonasaad2

    Joined:
    Nov 30, 2020
    Posts:
    51
    About removing objects, you should use SetActive, and not Destroy. Set Active leaves the object in the scene, but it is paused completely, and Destroy removes it from the scene, setting any script refers to that object blank.
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,144
    You wouldn't need a coroutine. Buttons have an onClick event that you just tie things to. So when the button is clicked, you just have it run some code.