void Update()
{
if (transform.position.y < GenerationPoint.position.y)
{
DistanceBetweenY = Random.Range(DistanceBetweenMinY, DistanceBetweenMaxY);
DistanceBetweenX = Random.Range(DistanceBetweenMinX, DistanceBetweenMaxX);
LeftorRightRNG = Random.Range(1, 3);
if (LeftorRightRNG == 1)
{
LeftorRightMultiplier = -1;
}
else if (LeftorRightRNG == 2)
{
LeftorRightMultiplier = 1;
}
transform.position = new Vector3(LeftorRightMultiplier * (transform.position.x + PlatformWidth + DistanceBetweenX), transform.position.y + PlatformHeight + DistanceBetweenY, transform.position.z);
DistanceBetweenCharacterPlatform = Vector2.Distance(transform.position, Character.THIS.transform.position);
Debug.Log(transform.position.ToString() + Character.THIS.transform.position.ToString());
if (DistanceBetweenCharacterPlatform > MaxDistanceBetweenCharacterPlatform)
{
}
else
{
Instantiate(Platform, transform.position, transform.rotation);
}
}
}
I’m starting out making a platformer project. I have this platform generator script, when the platforms spawn too far away from the player I want it to not spawn a platform and try again with a different randomly generated position. But after a few platforms spawn, they just stop and the function no longer runs. It’s in the update function so shouldn’t it keep trying? It seems like the end if statement continously just returns true and then they don’t spawn anymore. I’m quite stuck.