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

@@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="project">
<words>
<w>gameobject</w>
</words>
</dictionary>
</component>

View File

@@ -630,7 +630,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &1867692259
RectTransform:
m_ObjectHideFlags: 0

View File

@@ -7,11 +7,21 @@ namespace InterfaceOff
public WindowInteractions Interactions { get; set; }
public WindowComponents Components { get; set; }
public Vector3 Velocity { get; set; }
public void InstantiateWindowBase()
{
transform.position = CanvasManager.GetRandomPositionOnCanvas();
OnWindowInstantiation();
}
public void LateUpdate()
{
transform.position += Velocity * Time.deltaTime;
}
public virtual void OnWindowInstantiation() { }
public virtual void OnWindowClicked() { }
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
namespace InterfaceOff
{
@@ -31,9 +32,7 @@ namespace InterfaceOff
}
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
private void SpawnNewRandomWindow()
{
/* Creates the gameobject with a random class */
GameObject go = Instantiate(SampleChild, GameCanvas.transform);
@@ -49,12 +48,22 @@ namespace InterfaceOff
return;
}
/* 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)
{
SpawnNewRandomWindow();
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8cc86789c70b427d88ef6a4672547137
timeCreated: 1768302148

View File

@@ -0,0 +1,25 @@
using UnityEngine;
namespace InterfaceOff
{
public class MovingWindow : WindowBase
{
private int m_Health = 5;
public override void OnWindowInstantiation()
{
Components.WindowImage.color = Color.red;
Velocity = new Vector3(100, 100, 0);
}
public override void OnWindowClicked()
{
/* Decreases health and destroys if at 0 */
m_Health--;
if (m_Health <= 0)
{
Destroy(gameObject);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7ad1aa722804bbba796feea129247f1
timeCreated: 1768302389