Added a new moving window type
This commit is contained in:
7
.idea/.idea.Inter-Face-Off/.idea/dictionaries/project.xml
generated
Normal file
7
.idea/.idea.Inter-Face-Off/.idea/dictionaries/project.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="project">
|
||||
<words>
|
||||
<w>gameobject</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
||||
@@ -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
|
||||
|
||||
@@ -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() { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/Windows.meta
Normal file
3
Assets/Scripts/Windows.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8cc86789c70b427d88ef6a4672547137
|
||||
timeCreated: 1768302148
|
||||
25
Assets/Scripts/Windows/MovingWindow.cs
Normal file
25
Assets/Scripts/Windows/MovingWindow.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Windows/MovingWindow.cs.meta
Normal file
3
Assets/Scripts/Windows/MovingWindow.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7ad1aa722804bbba796feea129247f1
|
||||
timeCreated: 1768302389
|
||||
Reference in New Issue
Block a user