预制件的实例化比正常情况要大得多

时间:2018-07-19 20:28:19

标签: c# unity3d

我有以下问题: 我有一个预制件(有缝隙的地板),我在传递最后一个“地板”后在脚本中实例化了它。但是,如果预制件实例化了,它的实例尺寸将比普通预制件大得多(屏幕截图1)。

The small size white bar is the Prefab and the other 2 big one are the Instantiated ones

我使用的代码在以下屏幕截图中:

Script to Instantiate the next floor

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

此问题的解决方案将是

    GameObject Newfloor = Instantiate(FloorPrefab) as GameObject;
    NewFloor.Transform.SetParent(GameObject.Find("Gamescreen").transform);

使用

    Transform parent = GameObject.Find("Gamescreen").transform;
    GameObject NewFloor = Instantiate(FloorPrefab, parent) as GameObject;

这样,NewFloor会自动缩放到游戏屏幕的大小。