Пример #1
0
    GameObject CreateTile(int x, int y)
    {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Quad);

        go.transform.parent = SpaceParent;

        go.transform.localScale = Vector3.one * Grid.UnitSize;
        go.transform.position   = new Vector3(x * Grid.UnitSize, y * Grid.UnitSize, 1f);

        Material mat = (Material)GameObject.Instantiate(spaceMaterial);

        mat.mainTexture = SpaceGenerator.Create(new GridUnit(x + Grid.UnitSize, y + Grid.UnitSize));

        go.GetComponent <MeshRenderer>().sharedMaterial = mat;

        // float noise = Mathf.PerlinNoise( x + x/(float)Grid.UnitSize, y + y/(float)Grid.UnitSize );

        // Debug.Log(string.Format("noise: {0}, {1}, {2}", x, y, noise));

        for (int i = 0; i < Random.Range(0, 2); i++)
        {
            Vector3    pos      = new Vector3(Random.Range(-Grid.UnitSize / 2f, Grid.UnitSize / 2f), Random.Range(-Grid.UnitSize / 2f, Grid.UnitSize / 2f), -0.02f);
            GameObject asteroid = AsteroidGenerator.Create(Random.Range(1f, 24f), pos);

            asteroid.transform.position = pos + go.transform.position;
            asteroid.transform.parent   = go.transform;

            if (asteroid.GetComponent <PolygonCollider2D>().OverlapPoint(ship.transform.position))
            {
                Destroy(asteroid);
            }
        }

        return(go);
    }
Пример #2
0
 void Awake()
 {
     Current = this;
 }