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;
|
GameObject spawnedNeed = null;
|
||||||
|
@ -44,6 +44,8 @@ public class DeveloperNeeds : MonoBehaviour
|
||||||
if (spawnedNeed != null)
|
if (spawnedNeed != null)
|
||||||
{
|
{
|
||||||
spawnedNeed.transform.SetParent(transform, false);
|
spawnedNeed.transform.SetParent(transform, false);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class NPC_Behavior : MonoBehaviour
|
public class NPC_Behavior : MonoBehaviour
|
||||||
|
@ -34,24 +35,40 @@ public class NPC_Behavior : MonoBehaviour
|
||||||
|
|
||||||
private GameManager _gameManager;
|
private GameManager _gameManager;
|
||||||
private DeveloperNeeds _developerNeeds;
|
private DeveloperNeeds _developerNeeds;
|
||||||
private bool spawned = true;
|
[SerializeField] private float _timer;
|
||||||
|
private float _timeBetweenEvents;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
_gameManager = GameManager.Instance;
|
_gameManager = GameManager.Instance;
|
||||||
_developerNeeds = GetComponent<DeveloperNeeds>();
|
_developerNeeds = GetComponent<DeveloperNeeds>();
|
||||||
|
ResetTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
// fire event
|
_timer -= Time.deltaTime;
|
||||||
if (spawned)
|
|
||||||
|
if (_timer <= 0)
|
||||||
{
|
{
|
||||||
spawned = false;
|
List<string> needs = new List<string>() { "coffee", "mate", "toilet" };
|
||||||
List<string> needs = new List<string>() { "coffee", "mate", "toilet", "money" };
|
_developerNeeds.spawnNeed(needs[UnityEngine.Random.Range(0, needs.Count)]);
|
||||||
_developerNeeds.spawnNeed(needs[UnityEngine.Random.Range(0, 3)]);
|
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