【发布时间】:2019-05-28 15:43:26
【问题描述】:
我想更改函数中布尔值的状态。我的函数有 4 个参数,第四个是布尔值,默认为 true,但我想在函数内部将其状态更改为 false。
我正在调用我的方法,
SlotCheck("Red", "red_small_c", puzzle_9, GameControl.control.scoreRedGems, GameControl.control.stone_9);
GameControl.control.stone_9 默认为 true。一旦 visibilty 设置为 false,它应该变为 false ..但这并没有发生...stone_9 保持为真。
public void SlotCheck(string gemColor,string slotColor,GameObject puzzleStuk,int scoreGem,bool Visibility)
{
if (DragHandler2.itemBegingDragged.name.Contains(gemColor) && DragHandler2.itemBegingDragged.transform.parent.name == slotColor)
{
Debug.Log(DragHandler2.itemBegingDragged.name);
Visibility=false;
puzzleStuk.SetActive(visibility);
Debug.Log(GameControl.control.stone_9); //true
DragHandler2.itemBegingDragged.SetActive(false);
}
我希望 GameControl.control.stone_9 将其状态更改为 false,因为我将参数(可见性)的状态更改为 false,但 GameControl.control.stone_9 保持为 true。
【问题讨论】:
-
使用
ref传递布尔值,你需要这样做的原因是c#有引用访问,并且可以修改实际的布尔值,而不是克隆参数。