c# - C# 在脚本的另一部分中使用使用 Class 创建的变量
问题描述
尝试在函数中使用在脚本开头创建的带有类的变量。错误显示“当前上下文中不存在名称 'celula'”。
假设 celula.Name 必须返回“Cel1”。
public class ScreenC : MonoBehaviour
{
public void Start()
{
Cel celula = new Cel("Cel1", 30);
}
public class Cel
{
public string Name
{
get;
}
public int ATP
{
get;
set;
}
public Cel(string nm, int atp)
{
this.Name = nm;
this.ATP = atp;
}
}
public void ADDTHESE()
{ //here it seems to be the error
GameObject.Find(celula.Name).GetComponent<Text>().text = "ATP = 50";
}
}
解决方案
推荐阅读
- angular - 从父级的ajax调用接收数据后如何更新子组件
- express - 为什么 pug 页面不能在 express js 中呈现
- openlayers - Openlayers API 文档
- c# - MIN、MAX 堆叠图表中的指示(在这里停留了一个月..)
- c++ - 如何将 std::vector 设置为模板的默认参数?
- python - 停止将整个 pyhive 查询记录到日志文件
- php - 两者和形式
不能一起工作?在 html PHP - c# - Visual Studio 2013 的自定义代码分析
- c - 无法在 C 中使用带有 pow() 的模数
- sql-server - 出勤进出