1.Model
usingSystem;usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classModel:monobehaviour { Public intLevel ; Public intCoin; Public StaticModel instead; Public voidAwake () {instead= This; } //level Public intPlayerLevel {Get { returnLevel ; } Set{ level=value; } } //Gold coins Public intPlayercoin {Get { returnCoin; }Set{Coin=value; } }}
2.View
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine;usingUnityengine.ui; Public classView:monobehaviour { PublicText level; PublicText Coin; //Update is called once per frame voidUpdate () {Level.text=Model.instead.Level.ToString (); Coin.text=Model.instead.Coin.ToString (); } }
3.Controller
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityengine; Public classController:monobehaviour { Public StaticController instead; Public voidAwake () {instead= This; } //Use this for initialization voidStart () {}//Update is called once per frame voidUpdate () {} Public voidChangelevel () {Model.instead.PlayerLevel++; } Public voidChangecoin () {Model.instead.PlayerCoin+=Ten; }}
The simplest single-chain MVC