Made children randomly spawn
This commit is contained in:
@@ -435,6 +435,7 @@ GameObject:
|
|||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 1539476655}
|
- component: {fileID: 1539476655}
|
||||||
|
- component: {fileID: 1539476656}
|
||||||
- component: {fileID: 1539476654}
|
- component: {fileID: 1539476654}
|
||||||
- component: {fileID: 1539476653}
|
- component: {fileID: 1539476653}
|
||||||
- component: {fileID: 1539476652}
|
- component: {fileID: 1539476652}
|
||||||
@@ -528,6 +529,19 @@ RectTransform:
|
|||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 0, y: 0}
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
m_Pivot: {x: 0, y: 0}
|
m_Pivot: {x: 0, y: 0}
|
||||||
|
--- !u!114 &1539476656
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 1539476651}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: e090ce5928c145c0b2e514412bc9cdb2, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier:
|
||||||
|
<GameCanvas>k__BackingField: {fileID: 1539476654}
|
||||||
--- !u!1 &1683319378
|
--- !u!1 &1683319378
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
32
Assets/Scripts/CanvasManager.cs
Normal file
32
Assets/Scripts/CanvasManager.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace InterfaceOff
|
||||||
|
{
|
||||||
|
public class CanvasManager : MonoBehaviour
|
||||||
|
{
|
||||||
|
[field: SerializeField] public Canvas GameCanvas { get; private set; }
|
||||||
|
|
||||||
|
public static CanvasManager Instance { get; private set; }
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
if (DebugUtils.IsNull(Instance))
|
||||||
|
{
|
||||||
|
Instance = this;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.LogError("Multiple instances of Canvas Manager have been found");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector3 GetRandomPositionOnCanvas()
|
||||||
|
{
|
||||||
|
Rect rect = Instance.GameCanvas.pixelRect;
|
||||||
|
|
||||||
|
float x = Random.Range(rect.xMin, rect.xMax);
|
||||||
|
float y = Random.Range(rect.yMin, rect.yMax);
|
||||||
|
|
||||||
|
return new Vector3(x, y, 0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Scripts/CanvasManager.cs.meta
Normal file
3
Assets/Scripts/CanvasManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e090ce5928c145c0b2e514412bc9cdb2
|
||||||
|
timeCreated: 1768300347
|
||||||
@@ -8,6 +8,7 @@ namespace InterfaceOff
|
|||||||
|
|
||||||
public void InstantiateWindowBase()
|
public void InstantiateWindowBase()
|
||||||
{
|
{
|
||||||
|
transform.position = CanvasManager.GetRandomPositionOnCanvas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,14 @@ namespace InterfaceOff
|
|||||||
{
|
{
|
||||||
if (Input.GetKeyDown(KeyCode.Space))
|
if (Input.GetKeyDown(KeyCode.Space))
|
||||||
{
|
{
|
||||||
|
/* Creates the gameobject with a random class */
|
||||||
GameObject go = Instantiate(SampleChild, GameCanvas.transform);
|
GameObject go = Instantiate(SampleChild, GameCanvas.transform);
|
||||||
go.SetActive(true);
|
go.SetActive(true);
|
||||||
|
|
||||||
Type type = WindowTypes.GetRandom();
|
Type type = WindowTypes.GetRandom();
|
||||||
WindowBase windowBase = go.AddComponent(type) as WindowBase;
|
WindowBase windowBase = go.AddComponent(type) as WindowBase;
|
||||||
|
|
||||||
|
/* Checks it created correctly before instantiating further */
|
||||||
if (DebugUtils.IsNull(windowBase))
|
if (DebugUtils.IsNull(windowBase))
|
||||||
{
|
{
|
||||||
Debug.LogError("How did this happen");
|
Debug.LogError("How did this happen");
|
||||||
|
|||||||
Reference in New Issue
Block a user