Last active
May 4, 2017 20:18
-
-
Save neonima/2041a9cef63ad1b9ea8d0ce5a51c8f09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool InstiantiationCheck(GameObject GO, out GameObject instGo) | |
{ | |
instGo = null; | |
foreach (GameObject go in ObjectPoolList) | |
{ | |
if ( !ReferenceEquals(GO.GetComponent<PooledObject>(), null) && go.GetComponent<PooledObject>().nbrRef == GO.GetComponent<PooledObject>().nbrRef || GO.name.Equals(go.name) ) | |
{ | |
instGo = go; | |
return true; | |
} | |
} | |
if(!GO.GetComponent<PooledObject>()) | |
GO.AddComponent<PooledObject>(); | |
GameObject temp = Instantiate(GO, ObjectPool.transform); | |
PooledObject po = temp.GetComponent<PooledObject>(); | |
po.name = po.name.Replace("(Clone)", ""); | |
po.nbrRef = po.gameObject.GetHashCode(); | |
GO.GetComponent<PooledObject>().nbrRef = po.nbrRef; | |
po.mr = (GetComponent<MeshRenderer>()) ? GetComponent<MeshRenderer>() : GetComponentInChildren<MeshRenderer>(); | |
ObjectPoolList.Add(po.gameObject); | |
instGo = po.gameObject; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment