- Home /
This question was
closed Aug 05, 2016 at 01:29 AM by
PnguinMster7 for the following reason:
Other solved problem
Question by
PnguinMster7 · Jul 26, 2016 at 07:35 AM ·
2d game2d-gameplay
2D Endless runner spawning on top of each other?
I am creating my first game, it's a 2D endless runner, I have a problem where things spawn on top of each other. I have a coin system where they spawn randomly onto of the platform, and i have enemies that are still. they both keep spawning on top of each other. i use object pooling to spawn both the coin and the enemies. I've tried to research and tried many different ways to make it deactivate when it collides with the coin but i have not gotten it to work.This is what Spawns the Enemies/Coins.
if (Random.Range (0f, 100f) < randomCoinThresHold)
{
theCoinGenerator.SpawnCoins (new Vector3 (transform.position.x, transform.position.y + 1f, transform.position.z));
}
if (Random.Range (0f, 100f) < randomSealThreshold)
{
GameObject newSeal = sealPool.GetPooledObject ();
float sealXPosition = Random.Range (-platformWidths [platformSelector] / 2f + 1f, platformWidths [platformSelector] / 2f - 1f);
Vector3 sealPosition = new Vector3 (sealXPosition, 1f, 0f);
newSeal.transform.position = transform.position + sealPosition;
newSeal.transform.rotation = transform.rotation;
newSeal.SetActive (true);
}
and this is the coin generator script
public void SpawnCoins (Vector3 startPosition)
{
GameObject coin1 = coinPool.GetPooledObject ();
coin1.transform.position = startPosition;
coin1.SetActive (true);
GameObject coin2 = coinPool.GetPooledObject ();
coin2.transform.position = new Vector3(startPosition.x - disBetweenCoins, startPosition.y, startPosition.z);
coin2.SetActive (true);
GameObject coin3 = coinPool.GetPooledObject ();
coin3.transform.position = new Vector3(startPosition.x + disBetweenCoins, startPosition.y, startPosition.z);
coin3.SetActive (true);
}
I hope that you can help me out.
Comment
Follow this Question
Related Questions
Having some stuck issues on the 2D infinite runner 0 Answers
how to let user only have one go at moving? 1 Answer
Multiple Quests in Unity? 1 Answer