summaryrefslogtreecommitdiff
path: root/WorldlineKeepers/Assets/Scripts/Tests/TestSpirits.cs
blob: 8e46d3d5101ae4a72f218d2fd4cae55c01e1d987 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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<SpiritScript> spirits = new List<SpiritScript>();

    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();
        }
    }

}