Saturday, 29 July 2023

Variables between scripts

 If we want to access one variable (int data) from an external script, we must do:

1-ORIGINAL ONE.cs


   public static int data=0

2- SECOND TWO.cs

 

ONE.dinero = 1;

As u can see, the only secret its to declare "public static" your variable.

Of course, your 2 scripts must be on the same scene assigned to a GameObject.



Access external scripts

 

External scripts

WE HAVE A GENERAL SCRIPT (CONTAINS OUR FUNCTIONS)

1- OL1AScript.cs

WE HAVE OUR MAIN SCRIPT (2):

2- main.cs 

....

WE WANT TO ACCESS to (1) FROM OUR SCRIPT (2):



BOTH SCRIPTS MUST BE ASSIGNED TO A "GAMEOBJECT"  (create it on Unity, "Create Empty")

- Now, in "main.cs" (1) inside "public void Start"...
          OL1AScript ol1script = GetComponent<OL1AScript >();

          ol1script = GetComponent<OL1AScript >();

Saturday, 1 July 2023

Hola Mundo Unity

 Como hacer un primer programa muy sencillo tipo "Hola Mundo" en Unity:

Hola Mundo

Gracias a ACKOSMIC.com


 

Variables between scripts

 If we want to access one variable (int data) from an external script, we must do: 1-ORIGINAL ONE.cs     public static int data = 0 ;  2-...