mirror of
https://github.com/ryzij/Cube-Tower-Defense.git
synced 2026-07-14 01:56:57 +00:00
Добавил таймер для автоматического переключения волн
This commit is contained in:
@@ -3941,6 +3941,7 @@ Transform:
|
|||||||
- {fileID: 1282261902}
|
- {fileID: 1282261902}
|
||||||
- {fileID: 709556714}
|
- {fileID: 709556714}
|
||||||
- {fileID: 884308128}
|
- {fileID: 884308128}
|
||||||
|
- {fileID: 2072548927}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!1001 &486141168
|
--- !u!1001 &486141168
|
||||||
@@ -15645,6 +15646,52 @@ Transform:
|
|||||||
m_CorrespondingSourceObject: {fileID: 5368672011475721328, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
|
m_CorrespondingSourceObject: {fileID: 5368672011475721328, guid: 8dd20c91f0d7a7b419f6bedcd1870cba, type: 3}
|
||||||
m_PrefabInstance: {fileID: 2022833990}
|
m_PrefabInstance: {fileID: 2022833990}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
--- !u!1 &2072548926
|
||||||
|
GameObject:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
serializedVersion: 6
|
||||||
|
m_Component:
|
||||||
|
- component: {fileID: 2072548927}
|
||||||
|
- component: {fileID: 2072548928}
|
||||||
|
m_Layer: 0
|
||||||
|
m_Name: TurretBuildTimer
|
||||||
|
m_TagString: Untagged
|
||||||
|
m_Icon: {fileID: 0}
|
||||||
|
m_NavMeshLayer: 0
|
||||||
|
m_StaticEditorFlags: 0
|
||||||
|
m_IsActive: 1
|
||||||
|
--- !u!4 &2072548927
|
||||||
|
Transform:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2072548926}
|
||||||
|
serializedVersion: 2
|
||||||
|
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||||
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
|
m_ConstrainProportionsScale: 0
|
||||||
|
m_Children: []
|
||||||
|
m_Father: {fileID: 481586150}
|
||||||
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
|
--- !u!114 &2072548928
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 2072548926}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: 330d868d3d6a72c489dce65e1ca03edc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::TurretsBuildTimer
|
||||||
|
_gameManager: {fileID: 1875710079}
|
||||||
|
_buildTime: 10
|
||||||
--- !u!1001 &2096698926
|
--- !u!1001 &2096698926
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
public class TurretsBuildTimer : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private GameManager _gameManager;
|
||||||
|
[SerializeField] private float _buildTime = 10f;
|
||||||
|
[SerializeField] private UnityEvent<OnTickEventArgs> _onTick;
|
||||||
|
|
||||||
|
public event UnityAction<OnTickEventArgs> OnTick
|
||||||
|
{
|
||||||
|
add => _onTick.AddListener(value);
|
||||||
|
remove => _onTick.RemoveListener(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly WaitForSeconds _wait = new(1f);
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
_gameManager.OnStateChanged += OnStateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
_gameManager.OnStateChanged -= OnStateChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnStateChanged(GameManager.GameState newState)
|
||||||
|
{
|
||||||
|
if (newState == GameManager.GameState.BuildingPath)
|
||||||
|
return;
|
||||||
|
|
||||||
|
StopCoroutine(nameof(Timer));
|
||||||
|
if (newState == GameManager.GameState.BuildingTurrets)
|
||||||
|
StartCoroutine(nameof(Timer));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator Timer()
|
||||||
|
{
|
||||||
|
for (float i = 0; i < _buildTime; i++)
|
||||||
|
{
|
||||||
|
_onTick?.Invoke(new OnTickEventArgs
|
||||||
|
{
|
||||||
|
ElapsedSeconds = i,
|
||||||
|
TotalSeconds = _buildTime
|
||||||
|
});
|
||||||
|
yield return _wait;
|
||||||
|
}
|
||||||
|
|
||||||
|
_gameManager.NextLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OnTickEventArgs
|
||||||
|
{
|
||||||
|
public float SecondsLeft => TotalSeconds - ElapsedSeconds;
|
||||||
|
public float ElapsedSeconds { get; set; }
|
||||||
|
public float TotalSeconds { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 330d868d3d6a72c489dce65e1ca03edc
|
||||||
Reference in New Issue
Block a user