Hi, i know how to spawn 1 game object randomly between times but the problem is if i have more than 1 or more (im not decide yet how many)game object to spawn, how do i write for the code in c#? Please teach.
Always remember that spawn is used in network terms and Instance is used in local terms
Ok I know Javascript but ill try my best to Define my script in C#
import UnityEngine;
import System.Collections;
public GameObject[] ObjectsToSpawn;
void Update(){
if(Input.GetKey("space")){
Object.Instantiate(Objects[Random.Range(0,ObjectsToSpawn.length)]);
}
}
Now
Go to inspector
Find the script over there
Drag and drop the objects in the drop down called ObjectsToSpawn
Now How does this work?
In the Update function which is called every frame (Whenever the screen is repainted)
there is an if statement that waits for the Keyboard Input Space as a condition
When the condition is met it randomly chooses and Instantiates (Creates) a new GameObject from the list of GameObjects
Oh and plz mark my answer as correct
Go to inspector
Find the script over there
Drag and drop the objects in the drop down called ObjectsToSpawn