public void LoadIn() { var file = System.IO.File.ReadAllText(filePath); var jsonFile = JSON.Parse(file); var gameController = GameController.instance; foreach (var item in jsonFile.Keys) { Weapon.TypeOfWeapon type = (Weapon.TypeOfWeapon)Enum.Parse(typeof(Weapon.TypeOfWeapon), item.ToString()); var damage = jsonFile[item]["damage"]; var speed = jsonFile[item]["speed"]; var range = jsonFile[item]["range"]; //if the weapon is a gun it will excute GetDiagonalSizePlayarea() //instead of getting the data out of the JSON file if (range == "null") { var _range = Weapon.GetDiagonalSizePlayarea(gameController.width, gameController.depth); Weapon weapon = new Weapon(damage, speed, _range, type); WeaponDict.Add(type, weapon); return; } else { Weapon weapon = new Weapon(damage, speed, range, type); WeaponDict.Add(type, weapon); } } }
public Unit(int _health, int _strength, float _speed, int _defense, Weapon.TypeOfWeapon weapon) { this.health = _health; this.strength = _strength; this.speed = _speed; this.defense = _defense; this.weapon = WeaponController.WeaponDict[weapon]; }