在编写函数时,出现了error CS0122: 'CheckPoint.ResetCheckpoint()' is inaccessible due to its protection le的问题,排查后发现时ResetCheckpoint()函数设置的是私有变量改为public即可。
public void DeactivateCheckpoints()
{
for(int i = 0; i < checkpoints.Length; i++)
{
checkpoints[i].ResetCheckpoint();
}
}
更改前:
private void ResetCheckpoint()
{
theSR.sprite = cpOff;
}
更改后:
public void ResetCheckpoint()
{
theSR.sprite = cpOff;
}
一般来说,在 Unity 或其他 C# 编程环境中,出现错误 CS0122 意味着你尝试调用的方法(例如 ResetCheckpoint) 在其定义中是不可访问的。这通常是因为方法的访问修饰符(如 public、private、protected 或 internal)限制了其访问范围。