c# - Use of unassigned local variable `IsZoneEmpty' -
why saying use of unassigned variable iszoneempty
. i'm having hard time finding out why. because using variable in if statement.please me. why saying use of unassigned variable iszoneempty
. i'm having hard time finding out why. because using variable in if statement.please me.
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) gameobject; debug.log("monster spawned in zone 1"); } } } }
the first line in start()
method should changed
dictionary <vector3,bool> iszoneempty = new dictionary <vector3,bool>(); //(`;` `=`)
you can make smaller using var
var iszoneempty = new dictionary <vector3,bool>();
you should initialize variables before using them in c#
.
Comments
Post a Comment