我在名為 Grid 的腳本中設定了列舉,如下所示:
public enum CellType
{
Empty,
Road,
Structure,
SpecialStructure,
None
}
然后我有一個名為 placement manager 的腳本,它添加與該列舉相關的資料,如下所示:
internal void PlaceObjectOnTheMap(Vector3Int position, GameObject structurePrefab, CellType type, int width = 1, int height = 1)
{
StructureModel structure = CreateANewStructureModel(position, structurePrefab, type);
var structureNeedingRoad = structure.GetComponent<INeedingRoad>();
if (structureNeedingRoad != null)
{
structureNeedingRoad.RoadPosition = GetNearestRoad(position, width, height).Value;
Debug.Log("My nearest road position is: " structureNeedingRoad.RoadPosition);
}
for (int x = 0; x < width; x )
{
for (int z = 0; z < height; z )
{
var newPosition = position new Vector3Int(x, 0, z);
placementGrid[newPosition.x, newPosition.z] = type;
structureDictionary.Add(newPosition, structure);
DestroyNatureAt(newPosition);
}
}
}
最后,我有另一個名為 Grid Helper 的腳本,它應該呼叫 placement manager 并將其自身添加到我這樣設定的網格中:
public enum CellType
{
Empty,
Road,
Structure,
SpecialStructure,
None
}
[SerializeField]
private CellType structureType = CellType.Empty;
public PlacementManager placementManager;
// Start is called before the first frame update
void Start()
{
placementManager.PlaceObjectOnTheMap(new Vector3Int(Mathf.FloorToInt(transform.position.x),
Mathf.FloorToInt(transform.position.y),
Mathf.FloorToInt(transform.position.z)), this.gameObject, structureType);
}
但不知何故,我一直被告知 Argument3 無法從 GridHelper.CellType 轉換為 CellType。
我究竟做錯了什么?
uj5u.com熱心網友回復:
洗掉 GridHelper 或 Grid 類中的列舉,并根據洗掉的內容在其他類中使用 GridHelper.CellType 或 Grid.CellType。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536467.html
上一篇:實體化不顯示物件