player = {
}
local money;
function player.getMoney()
return money;
end
function player.setMoney(val)
money = val;
eventSystem.sendEvent("c", money);
if money <= 0 then
eventSystem.sendEvent("k", money <= 0);
end
end
function player.start()
player. setMoney(10);
end
mainPanel = {}
local txt;
local btn;
local function isdie(b)
print("model state".. tostring(b));
end
function mainPanel.awake()
btn = click.mono.transform:GetComponentInChildren(typeof(ui.Button));
txt = mainPanel.mono.transform:Find("Text"):GetComponent(typeof(engine.UI.Text));
eventSystem.addListener("c", mainPanel. updateMoney)
eventSystem.addListener("k",isdie)
end
function mainPanel.start()
end
function mainPanel.GetBtn()
return btn;
end
function mainPanel.updateMoney(num)
txt.text = tostring(num);
end
click = {}
local function BtnPress()
player.setMoney(player.getMoney() - 1);
end
function click.start()
mainPanel.GetBtn().onClick:AddListener(BtnPress)
end
function click.update()
end