最近在學Unity的一些用法,就看到"阿葉的影片"

教學滿有趣的也容易懂,所以我就一直看下去了,

影片連結 : https://www.youtube.com/watch?v=Euj2ncPbYaA

using UnityEngine;
using System.Collections;

public class proTest : MonoBehaviour {
    #region Struction
    [System.Serializable]
    public struct Hpstuff
    {
        public float HP;
        public float HP;
        public float HPbyLevel;
    }
    [System.Serializable]
    public struct Mpstuff
    {
        public float MP;
        public float MaxMP;
        public float MPbyLevel;
    }
    [System.Serializable]
    public struct Attackstuff
    {
        public float Attack;
        public float AttackbyLevel;
    }
    [System.Serializable]
    public struct stuff
    {
        public Hpstuff Hps;
        public Mpstuff Mps;
        public Attackstuff Atks;
    }
    #endregion
    public stuff warrior, wizard, archer, robber;
    void Start(){}
    void update(){}
}

從上面看到我們重覆用

[System.Serializable]
public struct Hpstuff

來幫我框住HP、MP、Attack等遊戲屬性,來結構化我們的變數,

讓自己or專案的其他工作者容易理解。

後面再利用一次的結構化來把Hpstuff、Mpstuff、Attackstuff 歸成一類,

在程式碼的最最後

public stuff warrior, wizard, archer, robber;

這是利用我們歸類出來的屬性,再歸類一次做應用職業(顧名思意就是戰士、巫師、弓手、盜賊)

你在Unity的Inspector的版面可以輕鬆看到你的職業與屬性

#region和 #endregion這兩個標籤,在程式中是不會被編譯進去的,

所以可以安心的用來管理你的程式碼區段,讓下次可以更快進入你程式的順序邏輯。

using UnityEngine;
using System.Collections;
public class proTest : MonoBehaviour {
    Struction
   public stuff warrior, wizard, archer, robber;
    void Start () { }
    void Update() { }
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Tars 的頭像
    Tars

    Tars的部落格

    Tars 發表在 痞客邦 留言(0) 人氣()