[英]How do I redefine a Vector3 array in unity C#?
我正在使用 Vector3 坐标数组,每次刷新时都需要根据新的锚点将其更新为新坐标(请参见下面的代码)。 但是这段代码不正确,我找不到任何明确的解决方案来重新定义数组。 我正在使用灵活大小的数组,因为在代码中的其他点删除了一些元素。 有没有更好的解决方案或重新定义数组的方法? 谢谢
public class Example : MonoBehavior {
public Vector3 anchorPoint;
Vector3[] locations;
// Various code
void OnRefresh() {
locations = {
new Vector3(anchorPoint.x + 1, anchorPoint.y, anchorPoint.z),
new Vector3(anchorPoint.x - 1, anchorPoint.y, anchorPoint.z),
new Vector3(anchorPoint.x, anchorPoint.y + 1, anchorPoint.z),
new Vector3(anchorPoint.x, anchorPoint.y - 1, anchorPoint.z),
new Vector3(anchorPoint.x, anchorPoint.y, anchorPoint.z + 1),
new Vector3(anchorPoint.x, anchorPoint.y, anchorPoint.z - 1)
};
}
}
您初始化数组的语法不正确:
----> locations = new[]{
new Vector3(anchorPoint.x + 1, anchorPoint.y, anchorPoint.z),
new Vector3(anchorPoint.x - 1, anchorPoint.y, anchorPoint.z),
new Vector3(anchorPoint.x, anchorPoint.y + 1, anchorPoint.z),
new Vector3(anchorPoint.x, anchorPoint.y - 1, anchorPoint.z),
new Vector3(anchorPoint.x, anchorPoint.y, anchorPoint.z + 1),
new Vector3(anchorPoint.x, anchorPoint.y, anchorPoint.z - 1)
};
您忘记了表示其数组的 new[]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.