c# - Unity3D - Error - Cannot implicitly convert type 'int' to 'string' -
my code listed here, coding rpg game, should not matter when comes helping me fix this. problem console keeps giving me:
assets/standard assets/scripts/base player/baseplayer.cs(20,21): error cs0029: cannot implicitly convert type 'int' 'string'
code:
using unityengine; using system.collections; public class baseplayer { private string playername; private int playerlevel; private basecharacterclass playerclass; private int speed; private int endurance; private int strength; private int health; public string playername{ get{return playername;} set{playername = value;} } public int playerlevel{ get{return playerlevel;} set{playername = value;} } public basecharacterclass playerclass{ get{return playerclass;} set{playerclass = value;} } public int speed{ get{return speed;} set{speed = value;} } public int endurance{ get{return endurance;} set{endurance = value;} } public int strength{ get{return strength;} set{strength = value;} } public int health{ get{return health;} set{health = value;} } }
here's mistake
public int playerlevel{ get{return playerlevel;} set{playername = value;} }
you're trying assign integer playername
in setter, playername
string, got error. should changed below
public int playerlevel{ get{ return playerlevel; } set{ playerlevel = value; } }
assuming baseplayer
class contains simple properties, can simplify code below using auto-implemented properties
public class baseplayer { public string playername { get; set; } public int playerlevel { get; set; } public basecharacterclass playerclass { get; set; } public int speed { get; set; } public int endurance { get; set; } public int strength { get; set; } public int health { get; set; } }
Comments
Post a Comment