From 7f4c15bf1c8a182d86235310368b217194e61889 Mon Sep 17 00:00:00 2001 From: klappstuhl24 Date: Fri, 5 Apr 2024 14:45:41 +0200 Subject: [PATCH] needs per minute = NPM implementiert --- 3d Prototyp/Assets/Scripts/DeveloperNeeds.cs | 4 ++- 3d Prototyp/Assets/Scripts/NPC_Behavior.cs | 29 ++++++++++++++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs b/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs index 8ec04083..0743b641 100644 --- a/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs +++ b/3d Prototyp/Assets/Scripts/DeveloperNeeds.cs @@ -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; } } diff --git a/3d Prototyp/Assets/Scripts/NPC_Behavior.cs b/3d Prototyp/Assets/Scripts/NPC_Behavior.cs index 6d2732f5..358adb7e 100644 --- a/3d Prototyp/Assets/Scripts/NPC_Behavior.cs +++ b/3d Prototyp/Assets/Scripts/NPC_Behavior.cs @@ -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(); + ResetTimer(); } // Update is called once per frame void Update() { - // fire event - if (spawned) + _timer -= Time.deltaTime; + + if (_timer <= 0) { - spawned = false; - List needs = new List() { "coffee", "mate", "toilet", "money" }; - _developerNeeds.spawnNeed(needs[UnityEngine.Random.Range(0, 3)]); + List needs = new List() { "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); } }