public GameObject GetNewEnemyFromType(Enumerations.EnemyType enemyType) { if (InactiveObjects.Exists(x => x.GetComponent(enemyType.ToString()))) { var poolObject = InactiveObjects.Find(x => x.GetComponent(enemyType.ToString())); var anim = GetComponentInChildren <Animator> (); anim.SetBool("isDead", false); ActiveObjects.Add(poolObject); InactiveObjects.Remove(poolObject); poolObject.transform.parent = transform; // Initialize happens later Enemy pooledEnemy = poolObject.GetComponent <Enemy>(); pooledEnemy.Repool(); poolObject.SetActive(true); return(poolObject); } //Debug.LogWarning(enemyType); var GO = PrefabPool.Find(x => x.GetComponent(enemyType.ToString()) != null); if (GO == null) { var msg = string.Format("No object found with type '{0}'.", enemyType); Debug.LogError(msg, gameObject); } var resultGO = GameObject.Instantiate(GO) as GameObject; ActiveObjects.Add(resultGO.gameObject); resultGO.transform.parent = transform; return(resultGO); }
public GameObject GetNewProjectileFromType(Enumerations.ProjectileTypes bulletType, Vector3 startPos, Quaternion startRot) { //Debug.Log(string.Format("Fetching object with type '{0}'.", bulletType)); if (InactiveObjects.Exists(x => x.GetComponent(bulletType.ToString()))) { Debug.Log(string.Format("Object found in pool.")); var poolObject = InactiveObjects.Find(x => x.GetComponent(bulletType.ToString())); ActiveObjects.Add(poolObject); InactiveObjects.Remove(poolObject); poolObject.transform.parent = transform; poolObject.transform.rotation = startRot; poolObject.SetActive(true); return(poolObject); } var GO = PrefabPool.Find(x => x.GetComponent(bulletType.ToString()) != null); if (GO == null) { var msg = string.Format("No object found with type '{0}'.", bulletType); Debug.LogError(msg, gameObject); } var resultGO = GameObject.Instantiate(GO, startPos, startRot) as GameObject; ActiveObjects.Add(resultGO.gameObject); resultGO.transform.parent = transform; return(resultGO); }