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

Random item generation.

Discussion in 'Scripting' started by StarGamess, Feb 1, 2015.

  1. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    So i made this system that randomly generates items. But everytime an item needs to be generated the game lags a bit for a few milliseconds this is probably because it needs to do so much in one call. The way the system work is i have a Script attached to a object called GameManager. Now everytime an enemy dies it calls a function in this script. And then this function sends back the randomly generated item.
    Code (CSharp):
    1. void GenItem ()
    2. {
    3.        dostuf;
    4.        domorestuf;
    5.  
    6.        sendgenerated object back;
    7. }
    Code (CSharp):
    1. void OnDead ()
    2. {
    3.         GameManager.Genitem();
    4. }
    now is there i way to reduce the lag. This might be very simple so if it sounds dumb but it might just work tell me anyway. Im still a little noob when it comes to these kind of things. ;p
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    Destroying your enemy might cause lag because of garbage collection, you could use an object pool. Generate items, same thing.
     
  3. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    Ohh thank you i will look into that.