示例#1
0
    void GenerateMap()
    {
        List <Transform> children = new List <Transform>();

        foreach (Transform child in transform)
        {
            children.Add(child);
        }
        foreach (Transform child in children)
        {
            if (Application.isPlaying)
            {
                Destroy(child.gameObject);
            }
            else
            {
                DestroyImmediate(child.gameObject);
            }
        }
        if (cellPrefab != null)
        {
            for (int i = 0; i < map.w; i++)
            {
                for (int j = 0; j < map.h; j++)
                {
                    Transform instance = Instantiate <Transform>(cellPrefab, RayTracer.GetCellPosition(new Cell(i, j)), Quaternion.identity, transform);
                    instance.transform.localScale          = new Vector3(1, Mathf.Max(0.01f, map.GetHeight(i, j)), 1);
                    instance.transform.localRotation       = Quaternion.Euler(new Vector3(0, 30, 0));
                    instance.GetComponent <MapCell>().cell = new Cell(i, j);
                }
            }
        }
    }