为什么这些游戏对象不能在Unity3D中实例化?
Why can't these gameobjects instantiate in Unity3D?
在下面的代码片段中,我试图以不同的概率实例化游戏对象,但我不断收到以下错误:
未找到参数列表“(Spawn06[])”的 'UnityEngine.Object.Instantiate' 的合适版本。
非常感谢您的帮助。谢谢
public var Characters : Spawn06[];
function SpawnCharacters() {
var i = Random.Range(0, 100);
for(var j = 0; j < Characters.Length; j++) {
if(i >= Characters [j].minProbabilityRange && i <= Characters [j].maxProbabilityRange) {
temp = Instantiate(Characters);
pos = temp.transform.position;
temp.transform.position = new Vector3(Random.Range(-3, 4), pos.y, pos.z);
}
}
}
public class Spawn06 {
public var spawnCharacters : GameObject;
public var minProbabilityRange : int = 0;
public var maxProbabilityRange : int = 0;
}
您不能将 class 的数组传递给实例化。
for(var j = 0; j < Characters.Length; j++) {
if(i >= Characters [j].minProbabilityRange && i <= Characters [j].maxProbabilityRange) {
temp = Instantiate(Characters[j].spawnCharacters); // Pass a GameObject instead of an Array of Spawn06
pos = temp.transform.position;
temp.transform.position = new Vector3(Random.Range(-3, 4), pos.y, pos.z);
}
}
}
在下面的代码片段中,我试图以不同的概率实例化游戏对象,但我不断收到以下错误:
未找到参数列表“(Spawn06[])”的 'UnityEngine.Object.Instantiate' 的合适版本。
非常感谢您的帮助。谢谢
public var Characters : Spawn06[];
function SpawnCharacters() {
var i = Random.Range(0, 100);
for(var j = 0; j < Characters.Length; j++) {
if(i >= Characters [j].minProbabilityRange && i <= Characters [j].maxProbabilityRange) {
temp = Instantiate(Characters);
pos = temp.transform.position;
temp.transform.position = new Vector3(Random.Range(-3, 4), pos.y, pos.z);
}
}
}
public class Spawn06 {
public var spawnCharacters : GameObject;
public var minProbabilityRange : int = 0;
public var maxProbabilityRange : int = 0;
}
您不能将 class 的数组传递给实例化。
for(var j = 0; j < Characters.Length; j++) {
if(i >= Characters [j].minProbabilityRange && i <= Characters [j].maxProbabilityRange) {
temp = Instantiate(Characters[j].spawnCharacters); // Pass a GameObject instead of an Array of Spawn06
pos = temp.transform.position;
temp.transform.position = new Vector3(Random.Range(-3, 4), pos.y, pos.z);
}
}
}