随着时间的流逝,我将如何使更多实体产生,从而使其变得更加困难

时间:2018-08-05 03:09:46

标签: c# unity3d

我的意思是我认为它会在标题中说出来,但是基本上我想知道让它变得炙手可热,这样我的游戏持续时间越长或执行相同操作的其他时间,isTimeToSpawn就会被激活得越多。

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {

public GameObject[] attackerPrefabArray;

// Update is called once per frame
void Update () {
    foreach (GameObject thisAttacker in attackerPrefabArray) {
        if (isTimeToSpawn (thisAttacker)) {
            Spawn (thisAttacker);
        }
    }   
}

void Spawn (GameObject myGameObject) {
    GameObject myAttacker = Instantiate (myGameObject) as GameObject;
    myAttacker.transform.parent = transform;
    myAttacker.transform.position = transform.position;
}

bool isTimeToSpawn (GameObject attackerGameObject) {
    Attacker attacker = attackerGameObject.GetComponent<Attacker>();

    float meanSpawnDelay = attacker.seenEverySeconds;
    float spawnsPerSecond = 1 / meanSpawnDelay;

    if (Time.deltaTime > meanSpawnDelay) {
        Debug.LogWarning ("Spwan rate capped by frame rate");
    }

    float threshold = spawnsPerSecond * Time.deltaTime / 5;

    return (Random.value < threshold);
}
}

1 个答案:

答案 0 :(得分:0)

您可以使用UnityEngine.Time中的变量之一。一种对您更有意义。那么您必须将其与您的Random混合。

例如

Random.Range(timeSinceLevelLoad, MaxValue);