"No overload for function "实例化“接受 4 个参数”

"No overload for function "instantiate" takes 4 arguments"

你好,我正在学习 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
            }
        }
    }

}

实例化方法给我带来了麻烦。甚至在线文档也说我可以传递 4 个参数,但我收到错误 "No overload for function "instantiate" takes 4 arguments"。 脚本组件附加到 Empty。

Unity3D's 5.3 documentation shows that there are no definitions for Object.Instantiate that takes four parameters. However, starting from 5.4,您可以根据需要使用 Instantiate 方法。请确保您的 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;
        }
    }
}