我想知道在对象上使用 C# 的 get 属性会返回什么,它是引用还是该属性分配给的副本?
据我了解,它实际上是返回副本而不是参考。对于下面的代码,我需要第 4 行来使 Position 工作(Position 是基类的属性)
Vector2 position = Position;
position.x = Mathf.Clamp(Position.x, 0, mScreenSize.x);
position.y = Mathf.Clamp(Position.y, 0, mScreenSize.y);
Position = position; //This line is required to clamp the position into Position