【发布时间】:2020-09-23 01:55:40
【问题描述】:
我试图在固定的 z 轴和随机的 x 轴点之间生成敌人。我正在让地面成为玩家的孩子,所以它会随着玩家移动。玩家只能在水平轴上移动。我想让它看起来像敌人总是在玩家面前产卵。我怎么能这样做?现在,如果我与玩家一起移动地面,敌人只会在指定点生成。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnManager : MonoBehaviour
{
[SerializeField] private GameObject _enemy;
// Start is called before the first frame update
void Start()
{
StartCoroutine(SpawnRoutine());
}
// Update is called once per frame
void Update()
{
}
IEnumerator SpawnRoutine()
{
while(true)
{
Vector3 PosToSpawn = new Vector3(Random.Range(-23.6f, 23.6f),1, 16.6f);
Instantiate(_enemy, PosToSpawn, Quaternion.identity);
yield return new WaitForSeconds(1f);
}
}
}
【问题讨论】: