This placement script it almost perfect, I just need a way to create a button in the inspector . I’d like to do this from within a monbehavoir script, and I have some assets that are monobehavoir scripts with buttons in their inspector so I think this is possible
using UnityEngine;
#if UNITY_EDITOR
//using Rage;
using UnityEditor;
#endif
using System.Collections;
//
//)
public enum Direction
{
Horizontal, Vertical, Z
}
//public enum Direction {Vertical , Horizontal }
[ExecuteInEditMode]
public class CustomPlace : MonoBehaviour
{//
public Transform NewParent ;
//public Action None;
public Direction CurrentDirection ;
public int Blocknum ;
public GameObject[] Blocks ;
public GameObject[] Spawned ;
public GameObject TemplateBlock ;
public Vector3 GotSize ;
public float SpawnNum ;
public bool GoingUP ;
public Vector3 AddPos ;
public string BlockName;
// ;
public bool ModSize ;
// if size isn't one
void OnGUI (){
if(GUI.Button(new Rect(10, 10, 50, 50),"Test")){
SpawnEm(Blocks[Blocknum]);
}
}
void SpawnEm (GameObject BlockNow) {
TemplateBlock = BlockNow ;
GotSize =
TemplateBlock.renderer.bounds.size ;
float i = 0 ;
while(i< SpawnNum){
i++;
switch(CurrentDirection)
{
case Direction.Horizontal:
BlockName = "HorBlock";
if(ModSize){
AddPos = new Vector3(GotSize.x*i,0,0);
}
else{
AddPos = new Vector3(i,0,0);
}
break;
case Direction.Vertical:
BlockName = "VerBlock";
if(ModSize){
AddPos = new Vector3(0,i*GotSize.y,0);
}
else{
AddPos = new Vector3(0,i,0);
}
break;
case Direction.Z:
BlockName = "ZBlock " ;
if(ModSize){
AddPos = new Vector3(0,0,i*GotSize.z);
}
else{
AddPos = new Vector3(0,0,i);
}
break;
}
//if(CurrentDirection.Horizontal){
// AddPos = new Vector3(0,i,0);
//}
//else
//{
// AddPos = new Vector3(0,i,0);
//}
if(ModSize){
//AddPos = AddPos*GotSize;
}
GameObject Current = Instantiate(TemplateBlock,
(TemplateBlock.transform.position
+ AddPos),TemplateBlock.transform.rotation) as GameObject;
Current.transform.parent = NewParent ;
Current.name = BlockName + i ;
Spawned[(int)(i-1)] = Current ;
}
}
void Up(){
GotSize =
TemplateBlock.renderer.bounds.size ;
}
}