Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ObjectPool : MonoBehaviour
- {
- private GameObject prefab;
- public GameObject prefabType1;
- public int objectNumType1;
- static private Stack StackObjType1Tmp = new Stack();
- static private Stack StackObjType1 = Stack.Synchronized(StackObjType1Tmp);
- void Awake()
- {
- int typeNum = 0;
- Stack StackObjTmp;
- typeNum = objectNumType1;
- prefab = prefabType1;
- StackObjTmp = StackObjType1;
- for (int j = 0; j < typeNum; j++)
- {
- GameObject gameObjectTmp = MonoBehaviour.Instantiate(prefab) as GameObject;
- gameObjectTmp.SetActive(false);
- StackObjType1.Push(gameObjectTmp);
- }
- }
- static public GameObject InstantiatePrefab(Vector3 position, Quaternion rotation)
- {
- GameObject obj = null;
- obj = (GameObject)StackObjType1.Pop();
- obj.transform.position = position;
- obj.transform.rotation = rotation;
- // Set the object to be active
- obj.SetActive(true);
- return obj;
- }
- static public void Destroy(GameObject objectToDestroy)
- {
- //Debug.Log("MyClass : param = " + param1 + ", " + param2);
- objectToDestroy.SetActive(false);
- StackObjType1.Push(objectToDestroy);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement