C# I';我是编程新手,我遇到一个错误CS7036
我得到了这个错误: 错误CS7036:未提供与“Wizard.Wizard”(字符串,浮点)的必需形式参数“health”对应的参数 Player.cs:C# I';我是编程新手,我遇到一个错误CS7036,c#,C#,我得到了这个错误: 错误CS7036:未提供与“Wizard.Wizard”(字符串,浮点)的必需形式参数“health”对应的参数 Player.cs: using UnityEngine; public class Player { private float health = 100f; private string name = "Default"; private float power = 100f; publi
using UnityEngine;
public class Player {
private float health = 100f;
private string name = "Default";
private float power = 100f;
public Player() { }
public Player(string name, float health) {
this.name = name;
this.health = health;
}
public float Health {
get {return health;}
set { health = value; }
}
public string Name {
get { return name;}
set { name = value;}
}
public virtual void Attack() {
Debug.Log("The Player is attacking");
}
// public void SetHealth(float health) {
// this.health = health;
//
// }
//
// public float GetHealth() {
// return this.health;
// }
public void PlayerInfo() {
Debug.Log("Player Name Is: " + name + " And Players Health Is: " + health);
}
}
public class Tester : MonoBehaviour {
void Start () {
Player p = new Player();
Wizard w = new Wizard ("Wizard, 34.123f");
w.PlayerInfo ();
// w.name = "Wizard";
// w.Health = 13.5f;
// print("\n");
// w.PlayerInfo ();
// w.ReplenishMana (33f);
}
}
public class Wizard : Player {
private float mana = 33f;
public Wizard() { }
public Wizard(string name, float health) {
this.Name = name;
this.Health = health;
}
public void ReplenishMana(float mana) {
this.mana = mana;
}
}
测试仪.cs:
using UnityEngine;
public class Player {
private float health = 100f;
private string name = "Default";
private float power = 100f;
public Player() { }
public Player(string name, float health) {
this.name = name;
this.health = health;
}
public float Health {
get {return health;}
set { health = value; }
}
public string Name {
get { return name;}
set { name = value;}
}
public virtual void Attack() {
Debug.Log("The Player is attacking");
}
// public void SetHealth(float health) {
// this.health = health;
//
// }
//
// public float GetHealth() {
// return this.health;
// }
public void PlayerInfo() {
Debug.Log("Player Name Is: " + name + " And Players Health Is: " + health);
}
}
public class Tester : MonoBehaviour {
void Start () {
Player p = new Player();
Wizard w = new Wizard ("Wizard, 34.123f");
w.PlayerInfo ();
// w.name = "Wizard";
// w.Health = 13.5f;
// print("\n");
// w.PlayerInfo ();
// w.ReplenishMana (33f);
}
}
public class Wizard : Player {
private float mana = 33f;
public Wizard() { }
public Wizard(string name, float health) {
this.Name = name;
this.Health = health;
}
public void ReplenishMana(float mana) {
this.mana = mana;
}
}
Wizard.cs:
using UnityEngine;
public class Player {
private float health = 100f;
private string name = "Default";
private float power = 100f;
public Player() { }
public Player(string name, float health) {
this.name = name;
this.health = health;
}
public float Health {
get {return health;}
set { health = value; }
}
public string Name {
get { return name;}
set { name = value;}
}
public virtual void Attack() {
Debug.Log("The Player is attacking");
}
// public void SetHealth(float health) {
// this.health = health;
//
// }
//
// public float GetHealth() {
// return this.health;
// }
public void PlayerInfo() {
Debug.Log("Player Name Is: " + name + " And Players Health Is: " + health);
}
}
public class Tester : MonoBehaviour {
void Start () {
Player p = new Player();
Wizard w = new Wizard ("Wizard, 34.123f");
w.PlayerInfo ();
// w.name = "Wizard";
// w.Health = 13.5f;
// print("\n");
// w.PlayerInfo ();
// w.ReplenishMana (33f);
}
}
public class Wizard : Player {
private float mana = 33f;
public Wizard() { }
public Wizard(string name, float health) {
this.Name = name;
this.Health = health;
}
public void ReplenishMana(float mana) {
this.mana = mana;
}
}
我是编程新手。我无法找出问题所在。应该是
新建向导(“向导”,34.123f)
。在代码中
newwizard(“Wizard,34.123f”)
被视为您只向方法传递了字符串
这里给您一个建议,请尝试正确格式化代码并使用正确的命名约定。应该是
新建向导(“向导”,34.123f)
。在代码中
newwizard(“Wizard,34.123f”)
被视为您只向方法传递了字符串
这里给您一个建议,请尝试正确格式化代码并使用正确的命名约定。您需要的参数是向导(字符串,浮点),因此您需要一个
字符串和一个浮点值作为参数,因此您必须这样编写代码:
new Wizard ("Wizard", 34.123f)
你的问题就会解决
传递参数时,必须以所需的格式传递参数。
这就是出现错误的原因。您需要的参数是向导(字符串,浮点),因此您需要一个字符串和一个浮点值作为参数,因此您必须这样编写代码:
new Wizard ("Wizard", 34.123f)
你的问题就会解决
传递参数时,必须以所需的格式传递参数。
这就是您出错的原因。您这样调用它:新建向导(“向导,34.123f”)
但它应该是这样的:新建向导(“向导”,34.123f)
,注意我在向导之后结束了字符串,因此,34.123f
成为第二个参数,而不是字符串的一部分。基本上,错误消息表示您没有传递健康,因为整个文本序列都是作为名称传递的。StackOverflow中不允许这样的非常基本的问题,请继续提问。您可能还应该将名称和运行状况传递给基类构造函数,这样您就不必自己设置名称和运行状况属性:public向导(字符串名称,浮点运行状况):base(姓名、健康状况){}
作为一般说明,粘贴代码时请删除所有不必要的行和空格。编辑此内容花了我很多时间,尤其是在我完成之前,其他人也对其进行了编辑,所以我尝试了4次!也不要包含不必要的代码,例如使用语句、注释代码等。您这样称呼它:新建向导(“向导,34.123f”)
但它应该是这样的:新建向导(“向导”,34.123f)
,请注意,我在向导之后结束了字符串,因此34.123f
成为第二个参数,而不是字符串的一部分。基本上,错误消息是说您没有在运行状况中传递,因为那里的整个文本序列都作为名称传递。StackOverflow中不允许这样的非常基本的问题询问他们您可能还应该将名称和运行状况传递给基类构造函数,这样您就不必自己设置名称和运行状况属性:public Wizard(string name,float health):base(name,health){
作为一般说明,粘贴代码时请删除所有不必要的行和空格。编辑此内容花费了我很多时间,尤其是在我完成之前,其他人也对其进行了编辑,所以我尝试了4次!也不要包含不必要的代码,例如使用语句、注释代码等。