public class ObjectPoolingManager : MonoBehaviour

{

ย  ย  public static ObjectPoolingManager instance;

ย  ย  public GameObject m_goPrefab =null;

ย  ย  public Queue m_queue = new Queue();

ย  ย  public int numOfobject;

ย  ย  Vector3 position;

ย  ย  void Awake()

ย  ย  {

ย  ย  ย  ย  instance = this;


ย  ย  ย  ย  for (int i = 0; i

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  GameObject t_object = Instantiate(m_goPrefab, Vector3.zero, Quaternion.identity);

ย  ย  ย  ย  ย  ย  t_object.GetComponent().position = Vector3.zero;

ย  ย  ย  ย  ย  ย  t_object.SetActive(false);

ย  ย  ย  ย  ย  ย  m_queue.Enqueue(t_object);


ย  ย  ย  ย  }


ย  ย  }


ย  ย  public void InsertQueue(GameObject p_object)

ย  ย  {

ย  ย  ย  ย  m_queue.Enqueue(p_object);

ย  ย  ย  ย  p_object.SetActive(false);

ย  ย  }


ย  ย  public GameObject GetQueue(Vector3 position)

ย  ย  {

ย  ย  ย  ย  GameObject t_object = m_queue.Dequeue();

ย  ย  ย  ย  t_object.GetComponent().position = position;

ย  ย  ย  ย  t_object.SetActive(true);

ย  ย  ย  ย  return t_object;

ย  ย  }

}

----------------------์—ฌ๊ธฐ๊นŒ์ง€๊ฐ€ ์˜ค๋ธŒ์ ํŠธ ํ’€๋ง ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. ์œ ํŠœ๋ธŒ์—์„œ ๊ฐ•์ขŒ๋ณด๊ณ  ๊ทธ๋Œ€๋กœ ์ผ์–ด์š”




public class Drop: MonoBehaviour

{

ย  ย  Rigidbody2D rigid;

ย  ย  void Awake() {

ย  ย  ย  ย  rigid = GetComponent();

ย  ย  }

ย  ย  void InsertDrop()

ย  ย  {

ย  ย  ย  ย  ObjectPoolingManager.instance.InsertQueue(gameObject);

ย  ย  }

ย  ย  void OnEnable() {

ย  ย  ย  ย  //gameObject.GetComponent().velocity = Vector3.zero;

ย  ย  ย  ย  rigid.AddForce(Vector3.down*3);

ย  ย  ย  ย  Invoke("InsertDrop", 4f);

ย  ย  }

ย  ย ย 

}


---------------- ์ด๊ฑด ์ œ๊ฐ€ ์ž‘์„ฑํ•œ ๋ฌผ๋ฐฉ์šธ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค(rigidbody2d, circlecollider๋ฅผ ๊ฐ€์ง„ ์˜ค๋ธŒ์ ํŠธํ”„๋ฆฌํŒน์ž…๋‹ˆ๋‹ค)

public class Generator : MonoBehaviour

{

ย  ย  public Vector3 position;


ย  ย  GameObject t_object;

ย  ย  Vector3 P;

ย  ย ย 

ย  ย  void Start()

ย  ย  {

ย  ย  ย  ย  P =transform.position;

ย  ย  ย  ย  createWater();

ย  ย  }

ย  ย ย 

ย  ย  void createWater()

ย  ย  {

ย  ย  ย  ย  t_object = ObjectPoolingManager.instance.GetQueue(P);

ย  ย  ย  ย  Invoke("createWater", 0.035f);

ย  ย  }

}

--------------------์ด๊ฑด generator ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.


generator๊ฐ€ 5๊ฐœ์ •๋„ ๋„˜์–ด๊ฐ€๋ฉด ๋ ‰์ด ์‹ฌํ•ด์ง€๋„ค์š” ์ œ ์ฝ”๋“œ๊ฐ€ ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š”๊ฑธ๊นŒ์š”??