Random Positioning

Help me, I need a script. I want to make three possible x-axis positions for a ball(gameobject). The script should randomly select a one x-axis position for the ball when a scene starts or loads.

using System;

private System.Random rdm;

public  Transform[] SpawnPoints;

void Awake()
{
   rdm = new System.Random();
}

void CreateRandomObjects()
{
      int randomSpawnPoint = rdm.Next(0,SpawnPoints.Lenght);
     GameObject obj = GameObject.Instantiate(PointObject,SpawnPoints[randomSpawnPoint].position,Quaternion.identity);
}

Next time think a bit more :wink:

1 Like