Accessing the variables of another class in C# Unity

Advertisemen

For those of you, who are using C# in unity3D. This short tutorial will show you how to access variables from other class in a vary simple way. You can use the same technique to get other contents from other classes.

For this tutorials, I have created two classes called ClassA and ClassB. So, In ClassA, I have the followings -


make sure that you have make variable public static otherwise code will not work.
In ClassB, I have these.
separator" style="clear: both; text-align: center;">

In this example, simply what I have done is ClassA.score so it is class name and the variable I want
to access.


If you want to have updated informations from ClassA, make sure that you have called the variable in side Update function, like this way.


Hope this is helpful to you guys. Thank you

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D