Hello, I am working on a tile based tactics game and would like to be able to use code to instantiate my tiles (and all of the data necessary). I know how to do this at run time, but I need to be able to make exceptions to what the general rules on a case by case basis.
Because of this, I would like to be able to, in the editor, programatically instantiate my network of tiles. From there, I could manually tweak the tiles. I want this to happen not during in-editor game play (CTRL P), so that it and my tweaks persist.
Thank you for your time.
The syntax to create gameobjects is the same as in runtime. You can either make a custom editor window to facilitate your game object creation, or use a MenuItem:
//Make sure to place this script in a folder called "Editor"
using UnityEditor;
public class MyTools
{
[MenuItem("MyTools/CreateGameObjects")]
static void Create()
{
for (int x=0; x!=10; x++)
{
GameObject go = new GameObject("MyCreatedGO"+i);
go.transform.position = new Vector3(x,0,0);
}
}
}
good luck, Lucas
Here is the above script with no errors and with creating the objects through Unity’s window GameObject/3D Object
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class CreateOBJ : MonoBehaviour {
[MenuItem("GameObject/3D Object/CreateGameObjects")]
static void Create()
{
for (int x = 0; x != 10; x++)
{
GameObject go = new GameObject("MyCreatedGO" + x);
go.transform.position = new Vector3(x, 0, 0);
}
}
}