Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: lzt120 on January 17, 2013, 03:42:18 AM

Title: Game Logic and UI
Post by: lzt120 on January 17, 2013, 03:42:18 AM
I am new to programming.My question is that should UI code and Game Logic code put into two seperate files and use the static method for the logic. UI Code just call that method's return value. for example:

Logic code :

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

   public static string GetStr(float i)
   {
      return i.ToString("f2");
   }
}


UI code:

using UnityEngine;
using System.Collections;

public class TestDisplay : MonoBehaviour {

   public UILabel lable;
   
   void Update ()
   {
      lable.text = Test.GetStr(Time.time);
   }
}
Title: Re: Game Logic and UI
Post by: Nicki on January 17, 2013, 04:44:40 AM
Not necessarily. Unity tends to couple view and game pretty closely, but you can do it any way you want. You can do it statically (no reason to have that as a monobehavior though), as a singleton, in components. Many ways to do it.

Having it statically will ensure that you only have a single value to read from, which is good for things like score, coins etc.