- Home /
Question by
itstimetomakelol · Jul 21, 2020 at 08:22 PM ·
c#2dinstantiateprefabprogramming
How to generate different diagonal platforms?
I'm making this game where you have slide down platforms (that are parallel) but had problems with generation. I made a little script that generates 10 of the same platforms parallel. But how do I randomly instantiate other prefabs? I tried with a random number generator and if statements but then the platforms wouldn't be parallel anymore.
[SerializeField] private Transform platforGen1;
[SerializeField] private Transform platforGen2;
[SerializeField] private Transform platforGen3;
[SerializeField] private Transform platforGen4;
[HideInInspector] private float nextPlatformYCord = 0f;
[HideInInspector] private float nextPlatformXCord = 0f;
private float numOfPlatforms = 10f;
int x = 1;
private void Awake()
{
do
{
SpawnPlatforGen1(new Vector2(10.33815f, -3.778132f) + new Vector2(nextPlatformXCord, nextPlatformYCord));
nextPlatformXCord += 16.31f;
nextPlatformYCord -= 10.49f;
x++;
} while (x <= numOfPlatforms);
}
private void SpawnPlatforGen1(Vector2 spawnPosition)
{
Instantiate(platforGen1, spawnPosition, Quaternion.identity);
}
Comment