为什么说使用未分配的变量isZoneEmpty
。我很难找出原因。因为我在if语句中使用了变量。请帮助我。为什么说使用未分配的变量isZoneEmpty
。我很难找出原因。因为我在if语句中使用了变量。请帮助我。使用未分配的本地变量`IsZoneEmpty'
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SpawnZone : MonoBehaviour
{
private Vector3 Zone1;
private Vector3 Zone2;
private Vector3 Zone3;
private Vector3 Zone4;
private Vector3 Zone5;
public Vector3 Zone1L;
public Vector3 Zone2L;
public Vector3 Zone3L;
public Vector3 Zone4L;
public Vector3 Zone5L;
public GameObject Monster;
GameObject SpawnedM;
void Start()
{
Dictionary <Vector3,bool> IsZoneEmpty; new Dictionary <Vector3,bool>();
{
IsZoneEmpty.Add(Zone1,true);
IsZoneEmpty.Add(Zone2,true);
IsZoneEmpty.Add(Zone3,true);
IsZoneEmpty.Add(Zone4,true);
IsZoneEmpty.Add (Zone5,true);
if (IsZoneEmpty[Zone1] == true)
{
SpawnedM = Instantiate(Monster,Zone1L, Quaternion.identity) as GameObject;
Debug.Log("Monster Spawned In Zone 1");
}
}
}
}
您声明了一个变量但不会初始化它。 'Dictionary IsZoneEmpty;''你需要像'Dictionary IsZoneEmpty = new Dictionary ();' –
Eser
我在代码中做了。 –
@DanSingh不,你没有 – dotnetom