【问题标题】:convert type 'Tile' to 'Tile[]' [duplicate]将类型'Tile'转换为'Tile []' [重复]
【发布时间】:2020-04-05 16:07:36
【问题描述】:

我在以下代码中收到错误cannot implicitly convert type 'Tile' to type 'Tile[]'.

public class GameManager : MonoBehaviour
{
    public Tile[,] AllTiles = new Tile [4,4];

    void Start()
    {
        // Error: cannot implicitly convert type 'Tile' to type 'Tile[]'.
        Tile[] AllTilesOnDim = GameObject.FindObjectOfType<Tile>();
        foreach (Tile t in AllTilesOnDim)
        {
            t.Number = 0;
            AllTiles[t.indRow, t.indCol]= t;
        }
    }
}

还有另一个类:

public class Tile : MonoBehaviour
{
    ....
}

【问题讨论】:

  • 您必须使用FindObjectsOfType 而不是FindObjectOfType

标签: c# arrays unity3d


【解决方案1】:

您必须使用FindObjectsOfType 而不是FindObjectOfType

也可以在这个链接上阅读它:Object.FindObjectsOfType

【讨论】:

  • @issamjallal 你可以接受这个答案来帮助别人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-14
  • 1970-01-01
  • 2012-09-27
  • 2017-07-17
  • 1970-01-01
  • 2013-06-01
  • 1970-01-01
相关资源
最近更新 更多