Added basic bouncing
This commit is contained in:
@@ -8,10 +8,12 @@ namespace InterfaceOff
|
||||
public class WindowSpawner : MonoBehaviour
|
||||
{
|
||||
private List<Type> WindowTypes { get; } = new();
|
||||
|
||||
|
||||
[field: SerializeField] private GameObject SampleChild { get; set; }
|
||||
[field: SerializeField] private Canvas GameCanvas { get; set; }
|
||||
|
||||
[field: SerializeField] public bool AutoSpawn { get; private set; } = true;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
/* Fetches all window types created */
|
||||
@@ -23,7 +25,7 @@ namespace InterfaceOff
|
||||
WindowTypes.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Logs the amount of types found and errors if there is none */
|
||||
Debug.Log($"Found [{WindowTypes.Count}] different window types ");
|
||||
if (WindowTypes.Count == 0)
|
||||
@@ -37,10 +39,10 @@ namespace InterfaceOff
|
||||
/* Creates the gameobject with a random class */
|
||||
GameObject go = Instantiate(SampleChild, GameCanvas.transform);
|
||||
go.SetActive(true);
|
||||
|
||||
|
||||
Type type = WindowTypes.GetRandom();
|
||||
WindowBase windowBase = go.AddComponent(type) as WindowBase;
|
||||
|
||||
|
||||
/* Checks it created correctly before instantiating further */
|
||||
if (DebugUtils.IsNull(windowBase))
|
||||
{
|
||||
@@ -51,18 +53,32 @@ namespace InterfaceOff
|
||||
/* Makes sure the WindowInteractions and WindowComponents are setup before passing to user code */
|
||||
windowBase.Interactions = go.GetComponent<WindowInteractions>();
|
||||
windowBase.Interactions.SetAttachedTo(windowBase);
|
||||
|
||||
|
||||
windowBase.Components = go.GetComponent<WindowComponents>();
|
||||
windowBase.InstantiateWindowBase();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
/* Checks if it should spawn a window */
|
||||
bool shouldSpawn = Random.Range(0, 40) == 0;
|
||||
if (shouldSpawn)
|
||||
if (AutoSpawn)
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
/* Checks if it should spawn a window */
|
||||
bool shouldSpawn = Random.Range(0, 40) == 0;
|
||||
if (shouldSpawn)
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!AutoSpawn)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
SpawnNewRandomWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user