C# &引用;“功能无过载”;实例化;取4个参数“;

C# &引用;“功能无过载”;实例化;取4个参数“;,c#,unity3d,unity5,C#,Unity3d,Unity5,您好,我正在学习Quill18制作的Unity教程。在我的代码中,我试图实例化一些十六进制预置 using UnityEngine; using System.Collections; public class HexMap : MonoBehaviour { // Use this for initialization void Start () { GenerateMap (); } public GameObject HexPrefab;

您好,我正在学习Quill18制作的Unity教程。在我的代码中,我试图实例化一些十六进制预置

using UnityEngine;
using System.Collections;

public class HexMap : MonoBehaviour {

    // Use this for initialization
    void Start () {
        GenerateMap ();
    }
    public GameObject HexPrefab;
    public void GenerateMap()
    {
        for (int column = 0; column < 10; column++) {
            for (int row = 0; row < 10; row++) 
            {
                Instantiate (HexPrefab, new Vector3 (column, 0, row), Quaternion.identity, this.transform); //this is the exact code he used and was working for him
            }
        }
    }

}
使用UnityEngine;
使用系统集合;
公共类HexMap:单行为{
//用于初始化
无效开始(){
GenerateMap();
}
公共游戏对象预置;
公共无效生成器映射()
{
for(int列=0;列<10;列++){
对于(int行=0;行<10;行++)
{
实例化(HexPrefab,新向量3(列,0,行),Quaternion.identity,this.transform);//这是他使用的和为他工作的代码
}
}
}
}
实例化方法给我带来了麻烦。甚至在线文档都说我可以传递4个参数,但是我得到了错误“函数没有重载”实例化“接受4个参数”。 脚本组件已附加到空的

显示没有对象的定义。实例化包含四个参数。但是,您可以按照预期使用实例化方法。确保您的Unity版本与本教程相同

对于Unity 5.3.x,更改实例化游戏对象父对象的解决方法如下:

public void GenerateMap()
{
    GameObject GO;
    for (int column = 0; column < 10; column++) {
        for (int row = 0; row < 10; row++) 
        {
            GO = Instantiate (HexPrefab, new Vector3 (column, 0, row), Quaternion.identity) as GameObject; 
            GO.transform.parent = this.transform;
        }
    }
}
public void GenerateMap()
{
游戏对象围棋;
for(int列=0;列<10;列++){
对于(int行=0;行<10;行++)
{
GO=实例化(HexPrefable,新矢量3(列,0,行),四元数.identity)作为游戏对象;
GO.transform.parent=this.transform;
}
}
}

确保您使用的是5.4或更高版本。我检查了一下,它说它是最新的:“unity editor是最新的。当前安装的版本是5.3.8p2”。当您遇到API问题时,第一个反应就是查看它的文档……很高兴您找到了答案。虽然我仍然不明白为什么你会收到“是最新的”消息,而实际上它并不是最新的稳定版本。我做了一个编辑,将GO的声明移动到一个更广泛的范围,以避免在循环的每一个步骤都有新的分配。