안녕 stackoverflow의 회원, 이것은 나의 첫 번째 질문 ...
겹치지 않고 무작위 스폰 지점에서 적을 스폰하고 싶습니다. 그래서, 스폰 포인트가 사용되면 그 스폰 포인트를 사용하지 않는지 확인하고 있습니다. 그렇지 않으면 계속합니다 ... 적에 대한 모든 spawnPoint를 포함하는 빈 게임 오브젝트가 있습니다. 빈 gameobejct에 스크립트를 할당했습니다.
Transform을 Spawn 포인트 목록으로 사용하려고했지만 안타깝게도 작동하지 않았습니다. 이것을 Vector3에서 Transform으로 변환 할 수 있다면 좋을 것입니다. Transform에서 이것을 변환하려고 시도했지만 너무 많은 오류가 발생했습니다. 시도했지만 예상대로 작동하지 않았습니다.
여기에서 해당 스크립트를 확인할 수 있습니다. 오류 스크립트 변환
다음과 같은 오류가 있습니다. 변환 오류
이제 제가 작업중인 스크립트는 다음과 같습니다.
using UnityEngine;
public GameObject enemy; //my enemy
public float spawnTime = 3f; //spawn after 3 sec
public List<Vector3> spawnPoints = new List<Vector3> (); //Vector3 positions of spawnpoints.
public float distance; //distance from the spawnPoints
void Start ()
{
//spawnRandom ();
InvokeRepeating ("spawnRandom", spawnTime, spawnTime); //Call this fucntion after 3sec.
}
public Vector3 spawnRandom(){
Vector3 newSpawnPoint; //new spawn point
Vector3 random = UnityEngine.Random.insideUnitSphere * distance;
newSpawnPoint = new Vector3 (random.x, 0, random.z);
newSpawnPoint += transform.position;
if (!spawnPoints.Contains (newSpawnPoint)) {
return newSpawnPoint;
spawnPoints.Add (newSpawnPoint);
int spawnIndex = Random.Range (0, spawnPoints.Count);
Instantiate (enemy, spawnPoints [spawnIndex].normalized, Quaternion.identity); //Spawn randomly
} else {
return Vector3.zero;}}
문제는 적이 스폰되지 않는다는 것입니다!
spawnPoints [spawnIndex] .normalized에서 생성하는 이유는 무엇입니까? newSpawnPoint에서 스폰해야합니다.
if 블록의 첫 번째 문은 return 문입니다. 마지막으로 이동합니다.
도움이 되길 바랍니다
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다