零基礎(chǔ)學(xué)做游戲 開始運(yùn)行起來吧

Hello World!

HelloWorld.cs

接上回


屏幕顯示結(jié)果.png

編寫代碼如下

using System.Collections;
using UnityEngine;

public class HelloWorld : MonoBehaviour
{
    public string stringTest = "Hello Game!";
    public bool boolTest = true;
    public float floatTest = 120.0f;
    public int intTest = 1;

    void Start()
    {
        stringTest = "Hello Gamers!";
        boolTest = true;
        floatTest = 99.99f;
        intTest = 1;

    }

}

運(yùn)行后顯示

運(yùn)行后顯示.png

public,private,static相關(guān)

using System.Collections;
using UnityEngine;

public class HelloWorld : MonoBehaviour
{
    public string stringTest = "Hello Game!";
    public bool boolTest = true;
    public float floatTest = 120.0f;
    public int intTest = 1;

    void Start()
    {
        stringTest = Test();//"Hello Gamers!";
        boolTest = bTest();
        floatTest = fTest();
        intTest = iTest();
    }

    private void Update()
    {

    }

    string Test()
    {
        return "Hello Game World!";
    }

    bool bTest()
    {
        return true;
    }

    float fTest()
    {
        return 0.01f;
    }

    int iTest()
    {
        return 1;
    }
}
運(yùn)行后顯示

轉(zhuǎn)換為靜態(tài)

using System.Collections;
using UnityEngine;

public class HelloWorld : MonoBehaviour
{
    public string stringTest = "Hello Game!";
    public bool boolTest = true;
    public float floatTest = 120.0f;
    public int intTest = 1;

    void Start()
    {
        stringTest = Test();//"Hello Gamers!";
        boolTest = HelloWorld.bTest(this);
        floatTest = HelloWorld.fTest(this);
        intTest = HelloWorld.iTest(this);
    }

    private void Update()
    {

    }

    string Test()
    {
        return "Hello Game World!";
    }

    static bool bTest(HelloWorld instance)
    {
        return true;
    }

    static float fTest(HelloWorld instance)
    {
        return 0.01f;
    }

    static int iTest(HelloWorld instance)
    {
        return 1;
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容