Search Unity

Help me with pooling system?What i do now??

Discussion in 'Scripting' started by dogdays, Oct 22, 2014.

  1. dogdays

    dogdays

    Joined:
    Oct 12, 2014
    Posts:
    9
    People i'm trying to do a pooling,but when i kill my enemy,i use setActive to kill him,but on pooling script,the enemy that i have just killed don't active again
    #pragma strict
    var headcannon : GameObject;
    var max : int;
    static var list = [];
    var timerepeat = 5 ;
    function Start () {
    max = 10;
    for(var list = 0; list < max; list++){
    {
    headcannon.SetActive(false);
    crear();
    active();
    //InvokeRepeating ("crear",timerepeat,timerepeat);
    }
    }
    }
    function Updatse () {
    }
    function crear () {
    Instantiate (headcannon , transform.position , transform.rotation);
    }
    function active () {
    if (!headcannon.activeInHierarchy)
    {
    headcannon.SetActive (true);
    }
    }
    i need when i kill my enemy they disable and then enable again but in another position...,it's the pooling method!
    Thanks in advance
     
  2. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    First of all, please use code tag. it's not that hard. ty.

    you need to create a list that holds all the entities.
    then when you need one you need to loop through the list and find one which is not activated, then activate it.

    Code (CSharp):
    1. function active () {
    2. if (!headcannon.activeInHierarchy)
    3. {
    4. headcannon.SetActive (true);
    5. }
    6. }
    7.  
    8.  
    this is not gona work since there are other headconnon in the Hierarchy.

    http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling
    it has everything yo need
     
    Habitablaba and Magiichan like this.
  3. dogdays

    dogdays

    Joined:
    Oct 12, 2014
    Posts:
    9
    #pragma strict
    var headcannon : GameObject;
    var max : int;
    static var list = [];
    var timerepeat = 0.5 ;
    function Start () {
    max = 10;
    for(var list = 0; list < max; list++){
    {
    headcannon.SetActive(false);
    InvokeRepeating ("active",timerepeat,timerepeat);
    }
    }
    }
    function Update () {
    }
    function crear () {
    Instantiate (headcannon , transform.position , transform.rotation);
    }
    function active () {
    if (!headcannon.activeInHierarchy) // activeinhierarchy faz para os filhos tbm,por isso usa-lo
    {
    for(var list = 0; list < max; list++){
    {
    crear ();
    headcannon.SetActive (true);
    }
    }
    }