(这是个纯C#工程的程序)
using System;
namespace MyConsole
{
class A {
public int x,y,z;
public A(int i,int j,int k){
x = i;
y = j;
z = k;
}
}
class MainClass
{
public static void Main (string[] args)
{
Console.WriteLine ("Hello World!");
A a, b;
a = new A (1, 1, 1);
b = a;
b.x = b.y = b.z = 2;
Console.WriteLine (a.x.ToString()+a.y.ToString()+a.z.ToString());
}
}
}
Unity的api里也有结构类型,比如Vector2.。。。(所以注意弄清哪些是结构哪些是类,结构是值类型,类是引用类型)
比如下面的代码,b的改变并不能改变a的值(新建一个场景,建一个Cube,把该代码加上):
using UnityEngine;
using System.Collections;
public class Reference : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector2 a = new Vector2 (1, 1);
//Vector2 b = a;
Vector2 b;
b = a;
b.x = 2;
b.y = 2;
Debug.Log (a);
}
}