- Home /
How to put assests into an array
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GameHandlerMapGeneration : MonoBehaviour { GameObject[] SpawnPointObj;
GameObject[] Obstacles;
public void Start()
{
SpawnPointObj = GameObject.FindGameObjectsWithTag("SpawnPoint");
foreach(GameObject SpawnPoint in SpawnPointObj)
{
print(SpawnPoint.transform.position);
int index = Random.Range(0, Obstacles.Length);
GameObject ObjBeingSpawned = Obstacles[index];
}
you see that game object array thing that is called Obstacles. I need that array to contain all the obstacles in my game (i have many objects like landmines speedbumps etc) but i have only 2 obstacles that are generateable. They are in the assets thing. They are in a folder called Obstacles. These obstacles are just groups of single objects. Like i have my first obstacle called 5 cones (its just 5 traffic cones) and 10 cones (its the same thing but more). i want these obstacles in the array but how???
Answer by Thygrrr · May 15 at 09:19 PM
Declare Obstacles as public or [SerializeField]
You can then add the assets in the inspector. There is a small lock icon at the top right of your objects inspector that you can click and then you can select multiple assets in a row and drag them over instead of one by one.
Your answer

Follow this Question
Related Questions
Deleted Data When Changing project name 2 Answers
Can I put scripts somewhere so they don't compile? 7 Answers
what exactly is shader? 1 Answer
No Assets! 1 Answer