Im trying to make a InspectorWindow which works lik the array modifier.
This is the code im using:
using UnityEngine;
using System.Collections;
using UnityEditor;
public class SpecialDuplicate : EditorWindow {
public GameObject ToDuplicate;
public Vector3 Pos;
public Vector3 Rot;
public Vector3 Scale;
public float Count;
private GameObject[] Duplicated = new GameObject[25];
public GameObject Prefab;
[MenuItem("Custom/Special Duplicate")]
public static void CreatespecialDuplicateWindow () {
EditorWindow.GetWindow (typeof(SpecialDuplicate));
}
void OnGUI () {
GUILayout.Label ("Select GameObject");
ToDuplicate = (GameObject)EditorGUILayout.ObjectField ("GameObject",ToDuplicate,typeof(GameObject));
GUILayout.Label ("Transform Difference");
Pos = EditorGUILayout.Vector3Field ("Position",Pos);
Rot = EditorGUILayout.Vector3Field ("Rotation",Rot);
Scale = EditorGUILayout.Vector3Field ("Scale",Scale);
GUILayout.Label ("Number of Duplcations");
Count = EditorGUILayout.FloatField ("Count",Count);
if(GUILayout.Button ("Duplicate"))
{
Prefab = PrefabUtility.CreatePrefab("Assets/CustomModifiers/Array/DuplicatingPrefab.prefab",ToDuplicate,ReplacePrefabOptions.Default);
for(int i = 0;i < Count;i++)
{
Duplicated *= (GameObject)Instantiate(Prefab,Vector3.zero,Quaternion.identity);*
-
if(i == 0)*
-
{*
_ Duplicated*.transform.position = new Vector3(ToDuplicate.transform.position.x + Pos.x,ToDuplicate.transform.position.y + Pos.y,ToDuplicate.transform.position.z + Pos.z);_
_ Duplicated.transform.rotation = new Quaternion(ToDuplicate.transform.rotation.x + Rot.x,ToDuplicate.transform.rotation.y + Rot.y,ToDuplicate.transform.rotation.z + Rot.z,0f) ;
Duplicated.transform.localScale = new Vector3(ToDuplicate.transform.localScale.x + Scale.x,ToDuplicate.transform.localScale.y + Scale.y,ToDuplicate.transform.localScale.z + Scale.z) ;*_
* }*
* else*
* {*
_ Duplicated*.transform.position = new Vector3(Duplicated[i - 1].transform.position.x + Pos.x,Duplicated[i - 1].transform.position.y + Pos.y,Duplicated[i - 1].transform.position.z + Pos.z);
Duplicated.transform.rotation = new Quaternion(Duplicated[i - 1].transform.rotation.x + Rot.x,Duplicated[i - 1].transform.rotation.y + Rot.y,Duplicated[i - 1].transform.rotation.z + Rot.z,0f) ;
Duplicated.transform.localScale = new Vector3(Duplicated[i - 1].transform.localScale.x + Scale.x,Duplicated[i - 1].transform.localScale.y + Scale.y,Duplicated[i - 1].transform.localScale.z + Scale.z) ;
}
Duplicated.transform.name = ToDuplicate.transform.name + (i + 1).ToString();
}
for(int i = 0;i < Count;i++)
{
Duplicated = null;
}
}
}
}*_
But when i try to access Duplicate in the script it shows the error: “IndexOutOfRangeException:Array index is out of range”.