我有一个基类和2个派生类.基类有一些简单的受保护浮点变量,我的基类的构造函数如下:
public Enemy(float _maxhp, float _damage)
{
maxhp = _maxhp;
health = _maxhp;
damage = _damage;
}
Run Code Online (Sandbox Code Playgroud)
但是,我的派生类Range还有2个浮点变量attack and attackSpeed需要在创建新实例时作为参数传入Range但我似乎无法做到这一点,因为There is no argument that corresponds to the required formal parameter '_maxhp' of 'Enemy.Enemy(float, float)'当我尝试使用构造函数进行派生时出现错误有这些参数的课程:
public Range(float _maxhp, float _damage, float _attack, float _attackSpeed)
但是具有相同数量的params的构造函数可以工作
public Range(float _maxhp, float _damage)
为什么会发生这种情况并且有某种解决方法?提前致谢.
我对内存和优化比较陌生。我的任务是优化一个现有项目,在查看 Unity 中的分析器时,我发现有一个函数会生成一堆东西供 GC 清理。
该函数是这样的:
public bool AnyCanvasOpen()
{
for (int i = 0; i < canvasList.Count; i++)
if (canvasList[i].activeSelf && canvasList[i].name != "MainUICanvas")
return true;
return false;
}
Run Code Online (Sandbox Code Playgroud)
其中 canvasList 只是游戏对象的列表。我的 282B 分配可能是什么原因?