public class PlatformSpawn : MonoBehaviour
{
public bool platformMaxed = false;
public static int platformSpawned;
public GameObject PlatformPre;
void Start ()
{
}
public void PlatformSpawning()
{
while (platformMaxed == false)
{
for (platformSpawned = 0 ;platformSpawned <= 10; platformSpawned++)
{
Instantiate (PlatformPre,
new Vector3(Random.Range(-15,15),Random.Range(1,15),0),
Quaternion.identity);
platformSpawned++;
//PlatformPre.collider.isTrigger = false;
Debug.Log("Platform Spawned" + platformSpawned);
if (platformSpawned >= 10)
{
platformMaxed = true;
break;
}
}
if (platformMaxed == true)
break;
}
}
void Update ()
{
if (platformSpawned <= 9)
{
PlatformSpawning();
}
}
}
Public static int platformSpawned is connected to another script here:
void OnCollisionEnter(Collision other)
{
Debug.Log("CollisionDetected");
if (other.collider.tag == "Platform")
{
Debug.Log("PlatformSpawned From Collision " + PlatformSpawn.platformSpawned);
Destroy(Platforms);
PlatformSpawn.platformSpawned--;
}
else
{
return;
}
}
For some reason the Debug.Log says it stops at anywhere around 5-8 platforms in the PlatformSpawn.cs.
In the PlatformCollision.cs it goes in the negative value.
So the question is: Why do the platforms stop being created even though the if statement is not met?