-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubeRandomGen.cs
More file actions
43 lines (35 loc) · 1.21 KB
/
Copy pathCubeRandomGen.cs
File metadata and controls
43 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class RandomGenWindow : EditorWindow
{
public Object ObjectToSpawn;
public Object TargetCube;
public int EncryptionCount = 1;
[MenuItem ("Tools/Random Encryption Placer")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(RandomGenWindow));
}
void OnGUI()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
ObjectToSpawn = EditorGUILayout.ObjectField("Object to Clone:", ObjectToSpawn, typeof(GameObject), true);
TargetCube = EditorGUILayout.ObjectField("Target Cube:", TargetCube, typeof(GameObject), true);
EncryptionCount = EditorGUILayout.IntSlider("Object Count:", EncryptionCount, 1, 100);
if (GUILayout.Button("Spawn Objects"))
{
for (int i = 0; i < EncryptionCount; i++)
{
SpawnObject(ObjectToSpawn, TargetCube);
}
}
}
public void SpawnObject(Object spawnableThing, Object targetLocation)
{
Vector3 rndPosWithin = targetLocation.transform.TransformPoint(Random.Range(-1f, 1f) * .5f, Random.Range(-1f, 1f) * .5f, Random.Range(-1f, 1f) * .5f);
Instantiate(spawnableThing, rndPosWithin, targetLocation.transform.rotation);
}
}