From 6dbca86d957f774059068b8dbe01170d71cb0e8f Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 29 Jun 2023 10:04:49 +0800 Subject: *misc --- .../Assets/Scripts/Tests/TestSpirits.cs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 WorldlineKeepers/Assets/Scripts/Tests/TestSpirits.cs (limited to 'WorldlineKeepers/Assets/Scripts/Tests/TestSpirits.cs') diff --git a/WorldlineKeepers/Assets/Scripts/Tests/TestSpirits.cs b/WorldlineKeepers/Assets/Scripts/Tests/TestSpirits.cs new file mode 100644 index 0000000..8e46d3d --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tests/TestSpirits.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UIElements; + +public class TestSpirits : MonoBehaviour +{ + public SpiritScript prefab; + + public static List spirits = new List(); + + private const int kMaxCount = 500; + + void Start() + { + int count = kMaxCount - spirits.Count; + for (int i = 0; i < count; ++i) + { + float x = UnityEngine.Random.Range(-20, 10); + float y = UnityEngine.Random.Range(-20, 10); + SpiritScript go = Instantiate(prefab) as SpiritScript; + go.transform.position = new Vector3(x, y, 0); + go.transform.parent = this.transform; + go.gameObject.SetActive(true); + } + StartCoroutine(CoSpawn(5)); + } + + IEnumerator CoSpawn(float interval) + { + while (true) + { + int count = kMaxCount - spirits.Count; + for (int i = 0; i < count; ++i) + { + float x = UnityEngine.Random.Range(-20, 10); + float y = UnityEngine.Random.Range(-20, 10); + SpiritScript go = Instantiate(prefab) as SpiritScript; + go.transform.position = new Vector3(x, y, 0); + go.transform.parent = this.transform; + go.gameObject.SetActive(true); + } + + yield return new WaitForSeconds(interval); + } + } + + private void FixedUpdate() + { + for(int i = 0; i < spirits.Count; ++i) + { + spirits[i].Tick(); + } + } + +} -- cgit v1.1-26-g67d0