gpt4 book ai didi

c# - 使用字符串变量访问其他脚本中的公共(public)变量

转载 作者:太空宇宙 更新时间:2023-11-03 21:01:08 25 4
gpt4 key购买 nike

我希望能够使用另一个脚本中的变量从一个脚本访问变量。例如,如果我有一个具有此变量的脚本:

public bool Some_Name;

在我的另一个脚本中我有这个:

private string nameOfThingToGet = "Some_Name";
...
GameObject.Find ("Player").GetComponent <FirstScript> () .nameOfThingToGet = false;

显然这行不通,但我怎么能做这样的事情呢?

最佳答案

在走这条路之前,您是否考虑过制作FirstScript暴露一个Dictionary<string, object>而不是使用字段?

这允许你做

GameObject.Find("Player").GetComponent<FirstScript>().dictionary[nameOfThin‌​gToGet] = false;

关于c# - 使用字符串变量访问其他脚本中的公共(public)变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com