im working at a infinit runner game and i want to add objectpooling to the platforms, but i got 2 errors:
Assets\PlatformGenerator.cs(37,26): error CS1501: No overload for method 'SpawnObject' takes 1 arguments
Assets\ObjectPool.cs(36,16): error CS0165: Use of unassigned local variable 'ToReturn'
Here is the platform generator script:
{
public GameObject ThePlatform;
public Transform GenerationPoint;
public float DistanceBetween;
private float PlatFormWidth;
public float DistanceBetweenMin;
public float DistanceBetweenMax;
public ObjectPool PlatformPool;
// Start is called before the first frame update
void Start()
{
PlatFormWidth = ThePlatform.GetComponent<BoxCollider2D>().size.x;
}
// Update is called once per frame
void Update()
{
if(transform.position.x < GenerationPoint.position.x)
{
DistanceBetween = Random.Range(DistanceBetweenMin, DistanceBetweenMax);
transform.position = new Vector3(transform.position.x + PlatFormWidth + DistanceBetween,
transform.position.y, transform.position.z);
//Instantiate(ThePlatform, transform.position, transform.rotation);
PlatformPool.SpawnObject(ThePlatform, transform.position, transform.rotation);
}
}
}
Here is the ObjectPooler script:
{
public GameObject ObjectToPool;
public List<GameObject> ThePool = new List<GameObject>();
public int StartAmount;
// Start is called before the first frame update
void Start()
{
for(int i = 0; i < StartAmount; i++)
{
ThePool.Add(Instantiate(ObjectToPool));
ThePool[i].SetActive(false);
ThePool[i].transform.parent = transform;
}
}
// Update is called once per frame
void Update()
{
}
public GameObject SpawnObject(Vector3 Position)
{
GameObject ToReturn;
ToReturn = ThePool[0];
ThePool.RemoveAt(0);
ToReturn.transform.position = Position;
ToReturn.SetActive(true);
return ToReturn;
}
}
hope you can help me because im new at programming and don't now hot fix things like this and if you see other things i should improve it would be very nice if you tell it me.