2

In unity (the game engine) I have two scripts

CharacterSelect.js
CarCameraScript.js

I want to access the variable

selectedPlayer

FROM characterSelect.js IN CarCameraScript.js

That variable currently looks like this:

var selectedPlayer : int = 0;

From what i hear is it has something to do with getcomponent. Any help would be appreciated

user3071284
  • 6,955
  • 6
  • 43
  • 57
user2966992
  • 13
  • 1
  • 4
  • 1
    if the variable is somehow accessible from the global scope, you should be able to access it in your other script, if it is included after the one, where the variable got declared. – hugo der hungrige Nov 10 '13 at 20:23

1 Answers1

2

you must create an instance of characterSelect.js in CarCameraScript.js

write in CarCameraScript.js

var characterSelectInstance : characterSelect;

characterSelectInstance = GameObject.Find("Name_Of_GameObjct_Where_you_attached_characterSelect.js").GetComponent(characterSelect);

so you can use it in CarCameraScript.js

var xyz : int ;
xyz = characterSelectInstance.selectedPlayer;
Dasu
  • 433
  • 6
  • 16