我如何使用vector3数组在列表中列出检查器中的所有vector3?

问题描述:

在脚本的顶部:我如何使用vector3数组在列表中列出检查器中的所有vector3?

public Vector3[] positionsList; 
List<Vector3> positions = new List<Vector3>(); 

在更新:我更新列表中,但我也想更新数组,所以我可以在游戏运行过程中,检查人员看的Vector3位置。

var position = GenerateRandomPositions(objects[0]); 

     if (!positions.Contains(position)) 
     { 
      positions.Add(position); 
     } 
+1

你的问题是什么? – Programmer

只要公开清单,检查员就可以处理它。

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 

public class ListInInspectorTest : MonoBehaviour { 

    public List<Vector3> superawesomeListOfVector3s; 

    void Update() { 

     if(superawesomeListOfVector3s.Count < 10) { 
      superawesomeListOfVector3s.Add(Random.insideUnitSphere); 
     } 

    } 
} 

如果重要的是该变量是私人的或保护其他代码。你可以在你想在检查器中看到的变量上添加[SerializeField]标签。来源(https://unity3d.com/learn/tutorials/topics/tips/show-private-variables-inspector