Added a new moving window type

This commit is contained in:
Pasha Bibko
2026-01-13 11:16:16 +00:00
parent eae7b615d6
commit e235c9e440
9 changed files with 78 additions and 21 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
namespace InterfaceOff
{
@@ -31,29 +32,37 @@ namespace InterfaceOff
}
}
private void Update()
private void SpawnNewRandomWindow()
{
if (Input.GetKeyDown(KeyCode.Space))
/* 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))
{
/* 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))
{
Debug.LogError("How did this happen");
return;
}
Debug.LogError("How did this happen");
return;
}
windowBase.Interactions = go.GetComponent<WindowInteractions>();
windowBase.Interactions.SetAttachedTo(windowBase);
/* 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();
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)
{
SpawnNewRandomWindow();
}
}
}