Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Oct 8, 2013

[Unity3d] How to access variables from other scripts

This is based on Unity 4.1. It might be different depending on Unity versions. 
Suppose that you want to access aaa.js from bbb.js. 

aaa.js

var nSource : int;  //  It doesn`t have to be  static, but private is not allowed here. 

bbb.js 

var src  : aaa;
function Start ()
{
      src =  FindObjectOfType(aaa);
}

Usage: 
function customFunction()
{
        var a = aaa.nSource; 
}