Hello World!
HelloWorld.cs
using System.Collections;
using UnityEngine;
public class HelloWorld: MonoBehaviour
{
public string text = "Hello Game!";
}
Console 显示无任何结果
Inspector 显示结果如下
using System.Collections;
using UnityEngine;
public class HelloWorld: MonoBehaviour
{
public string text = "Hello Game!";
public bool result = true;
public float posY = 120.00f;
public int member = 1;
}
Console 显示无任何结果
Inspector 显示结果如下
Inspector 可修改
错误代码:
using System.Collections;
using UnityEngine;
public class HelloWorld : MonoBehaviour
{
public string text = Hello Game!;
public bool result = yes;
public float posY = 120.00;
public int member = 1.2;
}
string
Assets/HelloWorld.cs(8,31): error CS1525: Unexpected symbol 'Game'
string为字符串类型,需加引号--""
bool
Assets/HelloWorld.cs(9,26): error CS0103: The name 'yes' does not exist in the current context
bool布尔值,范围True 或 False,默认值False
float
Assets/HelloWorld.cs(10,25): error CS0664: Literal of type double cannot be implicitly converted to type 'float'. Add suffix 'f' to create a literal of this type'
32 位单精度浮点型,范围-3.4 x 1038 到 + 3.4 x 1038,默认值0.0f
int
Assets/HelloWorld.cs(11,25): error CS0266: Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
32 位有符号整数类型,范围-2 , 147 , 483 , 648 到 2 , 147 , 483 , 647,默认值0
完整数据类型
using System.Collections;
using UnityEngine;
public class HelloWorld : MonoBehaviour
{
public bool boolTest;
public byte byteTest;
public char charTest;
public decimal decimalTest;
public double doubleTest;
public float floatTest;
public int intTest;
public long longTest;
public sbyte sbyteTest;
public short shortTest;
public uint unitTest;
public ulong ulongTest;
public ushort ushortTest;
public object objectTest;
public string stringTest;
}