从另一个CS文件填充公共字符串 [英] Populate public string from another cs file

查看:112
本文介绍了从另一个CS文件填充公共字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有2个文件的.cs feed.sc &安培; clickTest.sc 在clickTest.sc我有一个公共字符串链路ID =; 与我喜欢用信息来填充从 feed.sc

So i have 2 .cs files feed.sc & clickTest.sc in clickTest.sc i have a public string LinkID = ""; with i like to populate with information from feed.sc

不知道或如何做到这一点?

Not sure if or how to do this?

推荐答案

您使用 GameObject.Find 来找到游戏对象 clickTest 脚本连接到。然后使用 GetComponent 来获取附加到游戏对象 clickTest 脚本的实例。 ,其余是容易的。

You use GameObject.Find to find the GameObject the clickTest script is attached to. Then use GetComponent to get the instance of clickTest script that is attached to that GameObject. The rest is easy.

GameObject tempObj = GameObject.Find("Canvas/LiveFeed/Content/feeditem 0");
clickTest cTest = tempObj.GetComponent<clickTest>();
cTest.LinkID = "Hello!";

这篇关于从另一个CS文件填充公共字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆