Zombie-Zwischencommit
This commit is contained in:
parent
731c08bb97
commit
1b993db668
|
@ -427,7 +427,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_daysUntilRelease: 20
|
||||
_secondsPerDay: 30
|
||||
_secondsPerDay: 20
|
||||
_totalTime: 0
|
||||
_sun: {fileID: 179279866}
|
||||
--- !u!4 &227416519
|
||||
|
@ -461,7 +461,7 @@ GameObject:
|
|||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
m_IsActive: 0
|
||||
--- !u!4 &266099154
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -490,7 +490,7 @@ MonoBehaviour:
|
|||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
ZombiePrefab: {fileID: 856601670117699726, guid: a34b2d22562c7214f9daf0d3dea8d85c, type: 3}
|
||||
_spawnRate: 10
|
||||
_spawnRate: 2
|
||||
_spawnTimer: 0
|
||||
--- !u!1001 &514859708
|
||||
PrefabInstance:
|
||||
|
|
|
@ -11,9 +11,17 @@ public class Zeitschaltuhr : MonoBehaviour, ISerializationCallbackReceiver
|
|||
{
|
||||
private TimeSpan _turnOnTimeSpan;
|
||||
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;
|
||||
|
||||
|
||||
[SerializeField] private SimpleTime _turnOnTime;
|
||||
[SerializeField] private SimpleTime _turnOffTime;
|
||||
|
||||
|
@ -39,6 +47,7 @@ public class Zeitschaltuhr : MonoBehaviour, ISerializationCallbackReceiver
|
|||
|
||||
void Start()
|
||||
{
|
||||
CalculateOnTimeInSeconds();
|
||||
UpdateOn();
|
||||
}
|
||||
|
||||
|
@ -94,4 +103,23 @@ public class Zeitschaltuhr : MonoBehaviour, ISerializationCallbackReceiver
|
|||
_turnOnTimeSpan = _turnOnTime.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]
|
||||
GameObject ZombiePrefab;
|
||||
[SerializeField]
|
||||
private float _spawnRate = 1.0f;
|
||||
private float _spawnRate = 2.0f;
|
||||
[SerializeField, ShowOnly]
|
||||
private float _spawnTimer;
|
||||
|
||||
private float _secondsPerDay;
|
||||
private float _secondsPerAliveTime;
|
||||
|
||||
// Start wird aufgerufen, bevor das erste Frame gezeichnet wird
|
||||
void Start()
|
||||
{
|
||||
_secondsPerDay = (float)TimeManager.Instance.SecondsPerDay;
|
||||
_spawnTimer = _secondsPerDay / _spawnRate;
|
||||
_secondsPerAliveTime = GetComponentInParent<Zeitschaltuhr>().ActiveTimeSpanInSeconds;
|
||||
_spawnTimer = Random.Range(0.5f * _secondsPerAliveTime / _spawnRate, _secondsPerAliveTime / _spawnRate);
|
||||
}
|
||||
|
||||
// Update wird einmal pro Frame aufgerufen
|
||||
|
@ -29,7 +29,7 @@ public class ZombieSpawner : MonoBehaviour
|
|||
if (_spawnTimer <= 0)
|
||||
{
|
||||
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)
|
||||
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