needs per minute = NPM implementiert
This commit is contained in:
parent
e89ddca89b
commit
7f4c15bf1c
|
@ -18,7 +18,7 @@ public class DeveloperNeeds : MonoBehaviour
|
|||
|
||||
}
|
||||
|
||||
public void spawnNeed(string needName)
|
||||
public bool spawnNeed(string needName)
|
||||
{
|
||||
|
||||
GameObject spawnedNeed = null;
|
||||
|
@ -44,6 +44,8 @@ public class DeveloperNeeds : MonoBehaviour
|
|||
if (spawnedNeed != null)
|
||||
{
|
||||
spawnedNeed.transform.SetParent(transform, false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
|
||||
public class NPC_Behavior : MonoBehaviour
|
||||
|
@ -34,24 +35,40 @@ public class NPC_Behavior : MonoBehaviour
|
|||
|
||||
private GameManager _gameManager;
|
||||
private DeveloperNeeds _developerNeeds;
|
||||
private bool spawned = true;
|
||||
[SerializeField] private float _timer;
|
||||
private float _timeBetweenEvents;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_gameManager = GameManager.Instance;
|
||||
_developerNeeds = GetComponent<DeveloperNeeds>();
|
||||
ResetTimer();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// fire event
|
||||
if (spawned)
|
||||
_timer -= Time.deltaTime;
|
||||
|
||||
if (_timer <= 0)
|
||||
{
|
||||
spawned = false;
|
||||
List<string> needs = new List<string>() { "coffee", "mate", "toilet", "money" };
|
||||
_developerNeeds.spawnNeed(needs[UnityEngine.Random.Range(0, 3)]);
|
||||
List<string> needs = new List<string>() { "coffee", "mate", "toilet" };
|
||||
_developerNeeds.spawnNeed(needs[UnityEngine.Random.Range(0, needs.Count)]);
|
||||
ResetTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void ResetTimer()
|
||||
{
|
||||
if (eventRate <= 0)
|
||||
{
|
||||
_timeBetweenEvents = float.MaxValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
_timeBetweenEvents = 60f / (float)eventRate;
|
||||
_timer = Random.Range(0.5f * _timeBetweenEvents, 1.5f * _timeBetweenEvents);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue