Доступ к переменным в скриптах (или классах) в Unity не работаетC#

Место общения программистов C#
Гость
Доступ к переменным в скриптах (или классах) в Unity не работает

Сообщение Гость »


Я создаю игру в Unity, и мне нужна помощь с доступом к переменным в скриптах (или классах). У меня есть скрипт, который запускается на порожденном пустом объекте, и мой function looks like this:

Код: Выделить всё

Moneymanager moneymanager = GetComponent();
moneymanager.addMoney();
Invoke("despawn", 10f);
I just need there that when the object spawns, it will increase the amount of money of the player. In the canvas script, in

Код: Выделить всё

Update()
function, I have this:

Код: Выделить всё

moneyText.text = "$ " + playerMoney.ToString();
When I run it, the money doesn't increase. And I dont' know why:(.
I tried many types of accessing the variable of different class:

Код: Выделить всё

Moneymanager moneymanager;
Moneymanager moneymanager = new Moneymanager();
Moneymanager moneymanager = GetComponent();
but I didn't get working any of these.


Источник: https://stackoverflow.com/questions/781 ... ot-working

Вернуться в «C#»