零基础学做游戏 开始运行起来吧

Hello World!

HelloWorld.cs

接上回


屏幕显示结果.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;

    }

}

运行后显示

运行后显示.png

public,private,static相关

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;
    }
}
运行后显示

转换为静态

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;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容