团结(游戏引擎) 我有两个脚本
CharacterSelect.js
CarCameraScript.js
我想访问变量
selectedPlayer
FROM CarSeame.js IN CarCameraScript.js
该变量目前看起来像这样:
var selectedPlayer : int = 0;
据我所知,它与getcomponent有关。任何帮助将不胜感激
答案 0 :(得分:2)
您必须在CarCameraScript.js
中创建characterSelect.js的实例写在CarCameraScript.js
var characterSelectInstance : characterSelect;
characterSelectInstance = GameObject.Find("Name_Of_GameObjct_Where_you_attached_characterSelect.js").GetComponent(characterSelect);
所以你可以在CarCameraScript.js中使用它
var xyz : int ;
xyz = characterSelectInstance.selectedPlayer;