1. 程式人生 > >Unity中的結構體(C#)

Unity中的結構體(C#)

usingUnityEngine;
usingSystem.Collections;
  
public class Foo
{
    public Vector3 pos { get{ return _pos; } set{ _pos = value; } }
    private Vector3 _pos;
}
  
public class Demo : MonoBehaviour
{
    void Start ()
    {
        Foo myFoo = new Foo();
        myFoo.pos.Set(1, 2, 3);
        myFoo.pos.x = 4;
       //錯誤CS1612(參考上例,註釋掉本行編譯)
       Debug.Log(myFoo.pos.ToString());
       //輸出(0.0, 0.0, 0.0),並非預期值!
    }
}