gpt4 book ai didi

c# - 导致 Unity 崩溃的构造函数

转载 作者:行者123 更新时间:2023-12-02 00:06:29 25 4
gpt4 key购买 nike

代码

Army.Add(new PigSquad("The Old Guard", 10, 4));

哪里ArmyList<Unit>Pigsquad定义为

public class PigSquad : Unit
{
public override bool Dead { get; set; }
public override string Name { get; set;}
public override int Strength { get; set; }
public override int Age { get { return Age; } set { Age = value; Strength += 20 - Age; if (Age > 20) { Dead = true; } } }
public override int Veterancy { get; set; }
public PigSquad()
{

}
public PigSquad(string Name)
{
this.Name = Name;
}
public PigSquad(string Name, int Strength)
{
this.Name = Name;
this.Strength = Strength;
}
public PigSquad(string Name, int Strength, int Age)
{
this.Name = Name;
this.Strength = Strength;
this.Age = Age;
}
}

运行时 Unity 编辑器崩溃。我不知道这是为什么。对此的任何帮助将不胜感激。

最佳答案

public override int Age { get { return Age; } set { Age = value; Strength += 20 - Age; if (Age > 20) { Dead = true; } } }

应该是

private int _Age; //maybe make this in your UNIT object as well and that way you do not need it in your child.
public override int Age { get { return _Age; } set { _Age = value; Strength += 20 - _Age; if (Age > 20) { Dead = true; } } }

关于c# - 导致 Unity 崩溃的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49971445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com