Question by
Kamil1064 · Jun 28, 2016 at 06:35 PM ·
editor-scriptingcreatescriptable object
Wanna choose how many items create in editor C#
Hi, following to that tutorial http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects?playlist=17117 I've got:
public class MakeItems {
[MenuItem("Assets/Create/Myobject")]
public static void CreateMyObj()
{
//stuff inside
}
//To create multiple sctiptable object I'm using for loop:
[MenuItem("Assets/Create/Create 5 objects")]
public static void CreateFive()
{
for (int i = 0; i < 5; i++) {
CreateMyObj();
}
}
}
My question is: how to choose manually how many objects to create? For example after click "Create 5 objects" button, be able to write from keyboard?
Comment
Answer by PrisVas · Jun 28, 2016 at 07:30 PM
Change the "5" for a variable. And then you can put the value you whant in the variable and it will create the objects.
But where? Sorry, my fault, that may be important, It's not monobehaviour, just modyfied first post.
Answer by TCROC · Jun 29, 2016 at 07:38 PM
public class MakeItems {
public int howManyItemsToSpawn = 5;
[MenuItem("Assets/Create/Myobject")]
public static void CreateMyObj()
{
//stuff inside
}
//To create multiple sctiptable object I'm using for loop:
[MenuItem("Assets/Create/Create 5 objects")]
public static void CreateFive()
{
for (int i = 0; i < howManyItemsToSpawn; i++) {
CreateMyObj();
}
}
}
You can then edit the "howManyItemsToSpawn" variable.