【发布时间】:2017-10-22 17:49:29
【问题描述】:
我在使用 C# 使用 Unity/MonoDevelop 进行编码时遇到了一些问题。我想要做的是有 30 个不同的位置,但是使用随机发生器只有 20 个位置会生成一个预制件。我正在使用有关生成对象的 Youtube 频道 Gamad 教程 (https://www.youtube.com/watch?v=kTvBRkPTvRY) 修改脚本。 以下是我目前拥有的: `使用 System.Collections; 使用 System.Collections.Generic; 使用 UnityEngine;
公共类 SpawnObject : MonoBehaviour { public GameObject BeehivePrefab;
public Vector3 center;
public Vector3 size;
public Quaternion min;
public Quaternion max;
public int spawnCount = 0;
public int maxSpawns = 20;
public GameObject [] selectorArr;
// Use this for initialization
void Start () {
SpawnBeehive ();
}
// Update is called once per frame
void Update () {
while (spawnCount < maxSpawns){
int temp = Random.Range(0, selectorArr.length);
selectorArr[temp].Instantiate;
spawnCount++;
}
}
public void SpawnBeehive(){
Vector3 pos = center + new Vector3 (Random.Range (-size.x / 2, size.x / 2),Random.Range (-size.y / 2, size.y / 2), Random.Range (-size.z / 2, size.z / 2));
Instantiate (BeehivePrefab, pos, Quaternion.identity);
}
void OnDrawGizmosSelected(){
Gizmos.color = new Color (1, 0, 0, 0.5f);
Gizmos.DrawCube (transform.localPosition + center, size);
}
}` 在这段代码中,我在第 26 行和第 27 行(带有 int tem 和 selectorArr 的行)出现错误。
【问题讨论】:
标签: c# unity5 monodevelop