在调用Out方法时,确保将reset参数设置为false,这将确保变量不会自动重置。
例如:
bool myBool = true;
Debug.Log("My bool value is: " + myBool); // 输出 "My bool value is: True"
Debug.Log("My bool value is: " + myBool.ToString()); // 输出 "My bool value is: True"
myBool = false;
Debug.Log("My bool value is: " + myBool); // 输出 "My bool value is: False"
Debug.Log("My bool value is: " + myBool.ToString()); // 输出 "My bool value is: False"
// 以下代码会导致变量自动重置
myBool = true;
Debug.Log(myBool); // 只会输出 "True" 一次,接下来都会是 "False"
// 正确的写法应该是这样的:
myBool = true;
Debug.Log(myBool, reset: false); // 输出 "True"
Debug.Log(myBool, reset: false); // 输出 "True"
Debug.Log(myBool, reset: false); // 输出 "True"