[英]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.