- Home /
Duplicate Question
Javascript : Get variable & run a method from another script
I have this 3 javascript scripts :
GameSetup.js
function Start () {
// Run Map.Start
}
A function of Map.js
function Start () {
var map = new Array(6);
var i : int;
var j : int;
// We do this do avoid OutOfBounceException
for (i = 0; i < 6; i++) {
map[i] = new Array(6);
}
for (i = 0; i < 6; i++) {
for (j = 0; j < 6; j++) {
map[i][j] = -1;
}
}
and a function of BoxControl.js
function Update() {
var i : int;
var j : int;
if(Input.GetKey(moveUp)){
for (i = 2; i <= 5; i++) {
for (j = 2; j <= 5; j++) {
map[i][j] = 1;
}
}
1. I want to run the Map.Start function from the GameSetup.
2. And after creating the map I want to send the map array to the BoxControl so I can modify the map.
Accessing other game objects is the most frequently asked question on Unity Answers with 1000s of posts. Take a look at this link:
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
Note that 'Start()' in your $$anonymous$$ap.js will be called automatically after $$anonymous$$ap.js is attached to a game object.
Follow this Question
Related Questions
Accessing class properties through getters & setters in editor mode 1 Answer
Abstract Inheritance and abstract variables sloppy code 1 Answer
global variable doesn't work 2 Answers
C# generics and getters/setters with Unity iPhone 1 Answer
How to make a GLOBAL variable in javascript (Unity) 0 Answers