Hello World!
HelloWorld.cs
接上回
编写代码如下
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;
}
}
运行后显示
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;
}
}