unity报错NullReferenceException: Object reference not set to an instance of an object change.
publicGameObject[]character;publicintindex=0;privateGameObject[]charactershow;voidSta...
public GameObject[] character;
public int index = 0;
private GameObject[] charactershow;
void Start () {
}
void Update () {
if (Input.GetKey (KeyCode.G)) {
index += 1;
if (index >= character.Length) {
index = 0;
}
characterchange (index);
}
if (Input.GetKey (KeyCode.F)) {
index -= 1;
if (index < 0) {
index = character.Length - 1;
}
characterchange (index);
}
}
void characterchange(int inde){
for (int i = 0; i < character.Length; i++) {
if (i == inde) {
charactershow [i].SetActive (true);
} else
charactershow [i].SetActive (false);
// charactershow [i].active = false;
}
}
void instantiationcharacter(){
for (int i = 0; i < character.Length; i++) {
charactershow[i]=(GameObject)(Instantiate(character[i],transform.position,transform.rotation));
}
characterchange(index);
}
} 展开
public int index = 0;
private GameObject[] charactershow;
void Start () {
}
void Update () {
if (Input.GetKey (KeyCode.G)) {
index += 1;
if (index >= character.Length) {
index = 0;
}
characterchange (index);
}
if (Input.GetKey (KeyCode.F)) {
index -= 1;
if (index < 0) {
index = character.Length - 1;
}
characterchange (index);
}
}
void characterchange(int inde){
for (int i = 0; i < character.Length; i++) {
if (i == inde) {
charactershow [i].SetActive (true);
} else
charactershow [i].SetActive (false);
// charactershow [i].active = false;
}
}
void instantiationcharacter(){
for (int i = 0; i < character.Length; i++) {
charactershow[i]=(GameObject)(Instantiate(character[i],transform.position,transform.rotation));
}
characterchange(index);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询