diff --git a/MissileCommander/.idea/.idea.MissileCommander/.idea/contentModel.xml b/MissileCommander/.idea/.idea.MissileCommander/.idea/contentModel.xml
index 122f3b9..93fb9a7 100644
--- a/MissileCommander/.idea/.idea.MissileCommander/.idea/contentModel.xml
+++ b/MissileCommander/.idea/.idea.MissileCommander/.idea/contentModel.xml
@@ -18,6 +18,7 @@
+
diff --git a/MissileCommander/Assets/Scenes/SampleScene.unity b/MissileCommander/Assets/Scenes/SampleScene.unity
index 58a5bd1..4f3097e 100644
--- a/MissileCommander/Assets/Scenes/SampleScene.unity
+++ b/MissileCommander/Assets/Scenes/SampleScene.unity
@@ -148,7 +148,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1776773259}
- m_RootOrder: 5
+ m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &676322499
GameObject:
@@ -263,36 +263,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
---- !u!1 &972352209
-GameObject:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- serializedVersion: 6
- m_Component:
- - component: {fileID: 972352210}
- m_Layer: 0
- m_Name: BuildingLocator
- m_TagString: Untagged
- m_Icon: {fileID: 0}
- m_NavMeshLayer: 0
- m_StaticEditorFlags: 0
- m_IsActive: 1
---- !u!4 &972352210
-Transform:
- m_ObjectHideFlags: 0
- m_CorrespondingSourceObject: {fileID: 0}
- m_PrefabInstance: {fileID: 0}
- m_PrefabAsset: {fileID: 0}
- m_GameObject: {fileID: 972352209}
- m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
- m_LocalPosition: {x: 0, y: -4, z: 0}
- m_LocalScale: {x: 1, y: 1, z: 1}
- m_Children: []
- m_Father: {fileID: 1776773259}
- m_RootOrder: 3
- m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1082526252
GameObject:
m_ObjectHideFlags: 0
@@ -321,7 +291,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1776773259}
- m_RootOrder: 4
+ m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1092131172
GameObject:
@@ -390,7 +360,7 @@ MonoBehaviour:
buildingLocators:
- {fileID: 676322500}
- {fileID: 2063700999}
- - {fileID: 972352210}
+ - {fileID: 0}
- {fileID: 1082526253}
- {fileID: 598110664}
--- !u!4 &1776773259
@@ -407,7 +377,6 @@ Transform:
- {fileID: 1092131173}
- {fileID: 676322500}
- {fileID: 2063700999}
- - {fileID: 972352210}
- {fileID: 1082526253}
- {fileID: 598110664}
m_Father: {fileID: 0}
diff --git a/MissileCommander/Assets/_Scripts/BuildingManager.cs b/MissileCommander/Assets/_Scripts/BuildingManager.cs
index 57731f2..0b44fbe 100644
--- a/MissileCommander/Assets/_Scripts/BuildingManager.cs
+++ b/MissileCommander/Assets/_Scripts/BuildingManager.cs
@@ -17,8 +17,6 @@ public BuildingManager(Building buildingPrefab, Transform[] buildingLocators)
Debug.Assert(this._buildingPrefab != null, "BuildingManager : Prefab is null!");
Debug.Assert(this._buildingLocators != null, "BuildingManager : Locators are null!");
-
- SpawnBuildings();
}
public void SpawnBuildings()
@@ -36,5 +34,10 @@ public void SpawnBuildings()
_buildings.Add(building);
}
}
+
+ public void OnGameStart()
+ {
+ SpawnBuildings();
+ }
}
}
\ No newline at end of file
diff --git a/MissileCommander/Assets/_Scripts/BulletLauncher.cs b/MissileCommander/Assets/_Scripts/BulletLauncher.cs
index 84ed67e..7fae8c4 100644
--- a/MissileCommander/Assets/_Scripts/BulletLauncher.cs
+++ b/MissileCommander/Assets/_Scripts/BulletLauncher.cs
@@ -11,6 +11,7 @@ public class BulletLauncher : MonoBehaviour
[SerializeField] private float fireDelay = 0.5f;
private float _elapsedFireTime;
private bool _canShoot = true;
+ private bool _isGameStarted = false;
private Factory _bulletFactory;
private Factory _explosionFactory;
@@ -23,6 +24,8 @@ private void Awake()
private void Update()
{
+ if (!_isGameStarted) { return; }
+
if (!_canShoot)
{
_elapsedFireTime += Time.deltaTime;
@@ -34,8 +37,14 @@ private void Update()
}
}
+ public void OnGameStart()
+ {
+ _isGameStarted = true;
+ }
+
public void OnFireButtonPressed(Vector3 mousePosition)
{
+ if (!_isGameStarted) { return; }
if (!_canShoot) { return; }
// Instantiate Bullet
diff --git a/MissileCommander/Assets/_Scripts/GameManager.cs b/MissileCommander/Assets/_Scripts/GameManager.cs
index 3727c46..06bc9a4 100644
--- a/MissileCommander/Assets/_Scripts/GameManager.cs
+++ b/MissileCommander/Assets/_Scripts/GameManager.cs
@@ -5,6 +5,7 @@
* 2. Create instance of any GameController Class and assign it to BulletLauncher.
* ===================================================================================*/
+using System;
using UnityEngine;
namespace MissileCommander
@@ -15,19 +16,44 @@ public class GameManager : MonoBehaviour
[SerializeField] private Transform launcherLocator;
[SerializeField] private Building buildingPrefab;
[SerializeField] private Transform[] buildingLocators;
-
+
+ private MouseGameController _mouseGameController;
private BulletLauncher _launcher;
private BuildingManager _buildingMgr;
+ private TimeManager _timeMgr;
- private void Awake()
+ private void Start()
{
+ _timeMgr = gameObject.AddComponent();
+
_launcher = Instantiate(launcherPrefab);
_launcher.transform.position = launcherLocator.position;
_buildingMgr = new BuildingManager(buildingPrefab, buildingLocators);
+
+ _mouseGameController = gameObject.AddComponent();
+
+ BindEvents();
+ _timeMgr.StartGame();
+ }
- MouseGameController mouseController = gameObject.AddComponent();
- mouseController.OnFireButtonPressed += _launcher.OnFireButtonPressed;
+ private void OnDestroy()
+ {
+ UnbindEvents();
+ }
+
+ private void BindEvents()
+ {
+ _mouseGameController.OnFireButtonPressed += _launcher.OnFireButtonPressed;
+ _timeMgr.onGameStart += _buildingMgr.OnGameStart;
+ _timeMgr.onGameStart += _launcher.OnGameStart;
+ }
+
+ private void UnbindEvents()
+ {
+ _mouseGameController.OnFireButtonPressed -= _launcher.OnFireButtonPressed;
+ _timeMgr.onGameStart -= _buildingMgr.OnGameStart;
+ _timeMgr.onGameStart -= _launcher.OnGameStart;
}
}
}
\ No newline at end of file
diff --git a/MissileCommander/Assets/_Scripts/TimeManager.cs b/MissileCommander/Assets/_Scripts/TimeManager.cs
new file mode 100644
index 0000000..b0f4c01
--- /dev/null
+++ b/MissileCommander/Assets/_Scripts/TimeManager.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections;
+using UnityEngine;
+
+namespace MissileCommander
+{
+ public class TimeManager : MonoBehaviour
+ {
+ public event Action onGameStart;
+ private bool _isGameStarted = false;
+
+ public void StartGame(float startDelay = 1f)
+ {
+ if (_isGameStarted) { return; }
+
+ _isGameStarted = true;
+ StartCoroutine(DelayedGameStart(startDelay));
+ }
+
+ private IEnumerator DelayedGameStart(float delayTime)
+ {
+ WaitForSeconds delay = new WaitForSeconds(delayTime);
+ yield return delay;
+
+ onGameStart?.Invoke();
+ }
+ }
+}
\ No newline at end of file
diff --git a/MissileCommander/Assets/_Scripts/TimeManager.cs.meta b/MissileCommander/Assets/_Scripts/TimeManager.cs.meta
new file mode 100644
index 0000000..db0bb87
--- /dev/null
+++ b/MissileCommander/Assets/_Scripts/TimeManager.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 64e60fda42a141b3b253e53af00e643a
+timeCreated: 1575256716
\ No newline at end of file