Zombie-Zwischencommit
This commit is contained in:
parent
731c08bb97
commit
1b993db668
|
@ -427,7 +427,7 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
_daysUntilRelease: 20
|
_daysUntilRelease: 20
|
||||||
_secondsPerDay: 30
|
_secondsPerDay: 20
|
||||||
_totalTime: 0
|
_totalTime: 0
|
||||||
_sun: {fileID: 179279866}
|
_sun: {fileID: 179279866}
|
||||||
--- !u!4 &227416519
|
--- !u!4 &227416519
|
||||||
|
@ -461,7 +461,7 @@ GameObject:
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 1
|
m_IsActive: 0
|
||||||
--- !u!4 &266099154
|
--- !u!4 &266099154
|
||||||
Transform:
|
Transform:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -490,7 +490,7 @@ MonoBehaviour:
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
ZombiePrefab: {fileID: 856601670117699726, guid: a34b2d22562c7214f9daf0d3dea8d85c, type: 3}
|
ZombiePrefab: {fileID: 856601670117699726, guid: a34b2d22562c7214f9daf0d3dea8d85c, type: 3}
|
||||||
_spawnRate: 10
|
_spawnRate: 2
|
||||||
_spawnTimer: 0
|
_spawnTimer: 0
|
||||||
--- !u!1001 &514859708
|
--- !u!1001 &514859708
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
|
|
|
@ -11,7 +11,15 @@ public class Zeitschaltuhr : MonoBehaviour, ISerializationCallbackReceiver
|
||||||
{
|
{
|
||||||
private TimeSpan _turnOnTimeSpan;
|
private TimeSpan _turnOnTimeSpan;
|
||||||
private TimeSpan _turnOffTimeSpan;
|
private TimeSpan _turnOffTimeSpan;
|
||||||
|
private float _activeTimeSpanInSeconds;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Die Dauer der Active-Time der Kinder in echten Sekunden
|
||||||
|
/// </summary>
|
||||||
|
public float ActiveTimeSpanInSeconds => _activeTimeSpanInSeconds;
|
||||||
|
/// <summary>
|
||||||
|
/// Ob die Kinder gerade aktiv sind oder nicht
|
||||||
|
/// </summary>
|
||||||
public bool IsOn;
|
public bool IsOn;
|
||||||
|
|
||||||
[SerializeField] private SimpleTime _turnOnTime;
|
[SerializeField] private SimpleTime _turnOnTime;
|
||||||
|
@ -39,6 +47,7 @@ public class Zeitschaltuhr : MonoBehaviour, ISerializationCallbackReceiver
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
|
CalculateOnTimeInSeconds();
|
||||||
UpdateOn();
|
UpdateOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,4 +103,23 @@ public class Zeitschaltuhr : MonoBehaviour, ISerializationCallbackReceiver
|
||||||
_turnOnTimeSpan = _turnOnTime.ToTimeSpan();
|
_turnOnTimeSpan = _turnOnTime.ToTimeSpan();
|
||||||
_turnOffTimeSpan = _turnOffTime.ToTimeSpan();
|
_turnOffTimeSpan = _turnOffTime.ToTimeSpan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CalculateOnTimeInSeconds()
|
||||||
|
{
|
||||||
|
TimeSpan turnOnTimeSpan = _turnOnTime.ToTimeSpan();
|
||||||
|
TimeSpan turnOffTimeSpan = _turnOffTime.ToTimeSpan();
|
||||||
|
|
||||||
|
float onDurationInSeconds;
|
||||||
|
if (turnOnTimeSpan < turnOffTimeSpan)
|
||||||
|
{
|
||||||
|
onDurationInSeconds = (float)(turnOffTimeSpan - turnOnTimeSpan).TotalSeconds;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TimeSpan fullDay = TimeSpan.FromHours(24);
|
||||||
|
onDurationInSeconds = (float)((fullDay - turnOnTimeSpan) + turnOffTimeSpan).TotalSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
_activeTimeSpanInSeconds = onDurationInSeconds * ((float)TimeManager.Instance.SecondsPerDay / 86400f); // 86400 Sekunden pro Tag
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,17 +8,17 @@ public class ZombieSpawner : MonoBehaviour
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
GameObject ZombiePrefab;
|
GameObject ZombiePrefab;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float _spawnRate = 1.0f;
|
private float _spawnRate = 2.0f;
|
||||||
[SerializeField, ShowOnly]
|
[SerializeField, ShowOnly]
|
||||||
private float _spawnTimer;
|
private float _spawnTimer;
|
||||||
|
|
||||||
private float _secondsPerDay;
|
private float _secondsPerAliveTime;
|
||||||
|
|
||||||
// Start wird aufgerufen, bevor das erste Frame gezeichnet wird
|
// Start wird aufgerufen, bevor das erste Frame gezeichnet wird
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
_secondsPerDay = (float)TimeManager.Instance.SecondsPerDay;
|
_secondsPerAliveTime = GetComponentInParent<Zeitschaltuhr>().ActiveTimeSpanInSeconds;
|
||||||
_spawnTimer = _secondsPerDay / _spawnRate;
|
_spawnTimer = Random.Range(0.5f * _secondsPerAliveTime / _spawnRate, _secondsPerAliveTime / _spawnRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update wird einmal pro Frame aufgerufen
|
// Update wird einmal pro Frame aufgerufen
|
||||||
|
@ -29,7 +29,7 @@ public class ZombieSpawner : MonoBehaviour
|
||||||
if (_spawnTimer <= 0)
|
if (_spawnTimer <= 0)
|
||||||
{
|
{
|
||||||
Instantiate(ZombiePrefab, transform.position, Quaternion.identity, transform);
|
Instantiate(ZombiePrefab, transform.position, Quaternion.identity, transform);
|
||||||
_spawnTimer = _secondsPerDay / _spawnRate;
|
_spawnTimer = _secondsPerAliveTime / _spawnRate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,12 @@ public class ZombieSpawner : MonoBehaviour
|
||||||
// Destroy all children (zombies)
|
// Destroy all children (zombies)
|
||||||
for (int i = 0; i < transform.childCount; i++)
|
for (int i = 0; i < transform.childCount; i++)
|
||||||
{
|
{
|
||||||
Destroy(transform.GetChild(i).gameObject);
|
KillZombiesByDisable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void KillZombiesByDisable()
|
||||||
|
{
|
||||||
|
Destroy(transform.GetChild(i).gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue