Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 如何在侧视图中将视图实例化为栅格的预制件_Unity3d_Unity Container - Fatal编程技术网

Unity3d 如何在侧视图中将视图实例化为栅格的预制件

Unity3d 如何在侧视图中将视图实例化为栅格的预制件,unity3d,unity-container,Unity3d,Unity Container,我想在摄影机视图中创建一个类似栅格的视图,但我无法这样做。预制件将从摄影机视图中消失。有谁能帮我解决这个问题吗?我想将预制件放置为网格和9*6网格 public GameObject tilePrefab; Vector2 mapSize; void Start() { createGrid(); Debug.Log("Screen Width : " + Screen.width); Debug.Log("Screen

我想在摄影机视图中创建一个类似栅格的视图,但我无法这样做。预制件将从摄影机视图中消失。有谁能帮我解决这个问题吗?我想将预制件放置为网格和9*6网格

public GameObject tilePrefab;
    Vector2 mapSize;

    void Start()
    {
        createGrid();
        Debug.Log("Screen Width : " + Screen.width);
        Debug.Log("Screen Height : " + Screen.height);
        mapSize = new Vector2(Screen.width/9,Screen.height/12);
        Debug.Log("mapSize : " + mapSize);

    }


    void createGrid()
    {
        for (int x = 0; x < 9; x++)
        {
            for (int y = 0; y < 6; y++)
            {

                Vector3 tilePosition = new Vector3(-mapSize.x+0.5f + x,-mapSize.y + 0.5f+y ,0 );

                GameObject ballclone = (GameObject)Instantiate(tilePrefab,tilePosition,Quaternion.identity);
                ballclone.transform.parent = transform;

            }
        }
}
你可以用

对于int x=0;x<9;x++ 对于int y=0;y<6;y++ xx.position=camera.viewporttoWorldpoint新矢量31f/9*x,1f/6*y,距离;
距离是相机和对象之间的距离。

创建网格功能太差了。想想你想做什么,补偿应该是什么。此外,请确保您的相机是正交的,并记住屏幕大小!=可视区域