Hello, I am trying to institute a pool manager for my Instantiations but I can’t seem to access it from my script that needs to call for the pooled prefabs. I’ve looked through some other answers and tried everything suggested wit no luck. Could someone please take a look and let me know where I’m going wrong? Thank You
Pool Manager:
#pragma strict
import System.Collections.Generic;
var explosion : GameObject;
var willGrow : boolean = true;
private var pooledExplodes = new List.<GameObject> ();
private var headExplodeAmount : int;
function Start () {
for(var i : int = 0; i < headExplodeAmount; i++)
{
var obj : GameObject = Instantiate(explosion);
obj.SetActive(false);
pooledExplodes.Add(obj);
}
}
function GetPooledExplode() (GameObject) : GameObject {
for(var i : int = 0; i < pooledExplodes.Count; i++)
{
if(!pooledExplodes*.activeInHierarchy)*
-
{*
_ return pooledExplodes*;_
_ }_
_ }_
_ if(willGrow)_
_ {_
_ var obj : GameObject = Instantiate(explosion);_
_ pooledExplodes.Add(obj);_
_ return obj;_
_ }*_
* return null;*
* }*
Script that needs pooled explosions:
#pragma strict
import System.Collections.Generic;
var hitPoints = 100.0;
var damage = 5.0;
var PoolManager : GameObject;
function Start ()
{
var bodyDestroyObject : GameObject = GameObject.FindWithTag (“Zombie”);
if (bodyDestroyObject != null)
{
bodyDestroy = gameObject.GetComponentInParent (BodyDestroy2);
}
if (bodyDestroy == null)
{
Debug.Log (“Cannot find ‘BodyDestroy’ script”);
}
}
function ApplyDamage (damage : float) {
* if (hitPoints <= 0.0)*
* return;*
* hitPoints -= damage;*
* if (hitPoints <= 0.0) {*
PoolManager.GetPooledExplode();
* obj.transform.position = transform.position;*
* obj.transform.rotation = transform.rotation;*
* obj.SetActive(true);*
*} *
* Detonate ();*
* }*
function Detonate () {
* bodyDestroy.Kill();*
* hitPoints = 100.0;*
}