Hello, I am new to Unity. I have a little question. I’m programming game in c#. I stayed on the stage of generating obstacles in the game. I would like to make 30 kinds of obstacles (differing in size and animation), and generate from them in the game. (Something like obstacles in Flappy Bird, but these are diffent, not same). Anyone have an idea how to do it?
Create a public array of GameObjects in your script; in the inspector, populate that array with prefabs of your obstacles; then at regular intervals, randomly choose one of these to instantiate.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Platforms : MonoBehaviour
{
List<GameObject> prefabList = new List<GameObject>();
public GameObject Prefab1;
public GameObject Prefab2;
public GameObject Prefab3;
void Start()
{
prefabList.Add(Prefab1);
prefabList.Add(Prefab2);
prefabList.Add(Prefab3);
int prefabIndex = UnityEngine.Random.Range(0,1);
Instantiate(prefabList[prefabIndex]);
}
}