Search Unity

Give the function the time it need

Discussion in 'Scripting' started by Zeclown, Oct 13, 2015.

  1. Zeclown

    Zeclown

    Joined:
    Jul 27, 2014
    Posts:
    17
    Hey! I made a procedural dungeon script that execute on start. The project is 2d so when the grid is filled of "walls" and "floors" , I look at the walls dispositions and put the right wall sprite ,picking in a pool of 15 different ones. Then I choose random walls to put torches on them.The project is now slow to start since everything is done at start . When I hit the play button, it stops responding for 5-6 seconds before unfreezing. I know that start execute in one frame, so it freezes the game until the function executed completly. Is there a way to tell the game to carry on? To give more time to the function so it isn't so glitchy?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    You can use a coroutine for this. Or you can refactor it so that it you're doing a bit of work each time Update is called, until it's all done.