在第一个脚本中创建一个公共bool类型数组,并在第二个脚本中实例化第一个脚本。然后,可以在第二个脚本中调用第一个脚本的公共数组,将int类型的值传递给第一个脚本的bool数组。
示例代码如下:
第一个脚本:
public class FirstScript : MonoBehaviour { public bool[] boolArray;
// Start is called before the first frame update
void Start()
{
// set the bool array
boolArray = new bool[5];
}
}
第二个脚本:
public class SecondScript : MonoBehaviour { public int intValue;
// Start is called before the first frame update
void Start()
{
// instantiate the first script
FirstScript firstScript = GetComponent();
// get the bool array from the first script
bool[] boolArray = firstScript.boolArray;
// set the first value of the bool array to true if intValue is greater than 10
if (intValue > 10)
{
boolArray[0] = true;
}
}
}
上一篇:把调用外部API的业务逻辑放入SpringBatchwriter中是否是一个好主意?(用于将信息持久化到另一个系统)
下一篇:BadImageFormatException: 无法加载文件或程序集 'System.Net.Http' 或其依赖项之一