Exemple #1
0
 void DropOrbs()
 {
     if (canUseWeapon0)
     {
         OrbScript orb = Instantiate <OrbScript>(orbPrefab, transform.position + new Vector3(Random.Range(0f, 0.5f), 0.8f, Random.Range(0f, 0.5f)), Quaternion.identity);
         orb.weaponIndex = 0;
         orb.GetComponent <MeshRenderer>().material.SetColor("_Color", grid.colors[0]);
         orb.Drop();
     }
     if (canUseWeapon1)
     {
         OrbScript orb = Instantiate <OrbScript>(orbPrefab, transform.position + new Vector3(Random.Range(0f, 0.5f), 0.8f, Random.Range(0f, 0.5f)), Quaternion.identity);
         orb.weaponIndex = 1;
         orb.GetComponent <MeshRenderer>().material.SetColor("_Color", grid.colors[1]);
         orb.Drop();
     }
     if (canUseWeapon2)
     {
         OrbScript orb = Instantiate <OrbScript>(orbPrefab, transform.position + new Vector3(Random.Range(0f, 0.5f), 0.8f, Random.Range(0f, 0.5f)), Quaternion.identity);
         orb.weaponIndex = 2;
         orb.GetComponent <MeshRenderer>().material.SetColor("_Color", grid.colors[2]);
         orb.Drop();
     }
     if (canUseWeapon3)
     {
         OrbScript orb = Instantiate <OrbScript>(orbPrefab, transform.position + new Vector3(Random.Range(0f, 0.5f), 0.8f, Random.Range(0f, 0.5f)), Quaternion.identity);
         orb.weaponIndex = 3;
         orb.GetComponent <MeshRenderer>().material.SetColor("_Color", grid.colors[3]);
         orb.Drop();
     }
 }
Exemple #2
0
    void Awake()
    {
        foreach (Transform t in transform)
        {
            Destroy(t.gameObject);
        }

        buildingLayerMask = LayerMask.GetMask("Buildings");

        // random temple start positions
        temples[0] = new Vector3(Mathf.Floor(Random.Range(1, 4)), 0, Mathf.Floor(Random.Range(1, 4)));
        temples[1] = new Vector3(Mathf.Floor(Random.Range(1, 4)), 0, Mathf.Floor(Random.Range(5, 9)));
        temples[2] = new Vector3(Mathf.Floor(Random.Range(5, 9)), 0, Mathf.Floor(Random.Range(1, 4)));
        temples[3] = new Vector3(Mathf.Floor(Random.Range(5, 9)), 0, Mathf.Floor(Random.Range(5, 9)));

        int   orbRandomizer = Random.Range(0, templesCount);
        float noiseOffset   = Random.Range(0f, 100f);

        squares = new Square[gridWidth * gridHeight];
        for (int x = 0; x < gridWidth; x++)
        {
            for (int z = 0; z < gridHeight; z++)
            {
                int   i = x * gridWidth + z;
                float y = Mathf.PerlinNoise((float)x / gridWidth + noiseOffset, (float)z / gridHeight + noiseOffset) * heightScale;

                squares[i].cube = Instantiate(floorPrefab, new Vector3(x + .5f, y - 1, z + .5f), Quaternion.identity);
                squares[i].cube.transform.parent = transform;
                squares[i].color = Color.Lerp(lowColor, highColor, y * (1 - minHeight) + minHeight);
                squares[i].top   = squares[i].cube.transform.position + new Vector3(0, squares[i].cube.transform.localScale.y / 2, 0);

                SpriteRenderer cubeSprite = squares[i].cube.GetComponentInChildren <SpriteRenderer>();
                cubeSprite.sprite = floorSprites[Random.Range(0, floorSprites.Length)];
                cubeSprite.color  = squares[i].color;

                Color buildingColor = Color.Lerp(lowColor, highColor, ((y - .5f) * buildingColorDamp + .5f) * (1 - minHeight) + minHeight);

                // place temples and orbs
                bool templePlaced = false;
                for (int j = 0; j < templesCount; j++)
                {
                    if (x == temples[j].x && z == temples[j].z)
                    {
                        OrbScript orb = Instantiate <OrbScript>(orbPrefab, new Vector3(x + .5f, y + .8f, z + .5f), Quaternion.Euler(0, 0, 0));
                        orb.weaponIndex = (j + orbRandomizer) % templesCount;
                        orb.GetComponent <MeshRenderer>().material.SetColor("_Color", colors[orb.weaponIndex]);
                        orb.GetComponent <MeshRenderer>().enabled = false;

                        TempleScript temple = Instantiate <TempleScript>(templePrefab, new Vector3(x + .5f, y, z + .5f), Quaternion.Euler(0, 0, 0));
                        templePlaced = true;
                        temple.transform.Find("Base").GetComponent <SpriteRenderer>().color = buildingColor;
                        temple.transform.Find("Mask").GetComponent <SpriteRenderer>().color = colors[orb.weaponIndex];
                        temple.orb = orb;
                    }
                }

                // place buildings
                if (!templePlaced && Mathf.Abs(x - z) < Mathf.Min(gridWidth, gridHeight) - 3)
                {
                    if (Random.value < buildingChance)
                    {
                        GameObject     building       = Instantiate(buildingPrefab, new Vector3(x + .5f, y, z + .5f), Quaternion.identity);
                        SpriteRenderer buildingSprite = building.GetComponentInChildren <SpriteRenderer>();
                        buildingSprite.sprite = buildingSprites[Random.Range(0, buildingSprites.Length)];
                        buildingSprite.color  = buildingColor;
                    }
                    else if (Random.value < eggChance)
                    {
                        Instantiate(eggPrefab, new Vector3(x + .5f, y, z + .5f), Quaternion.identity);
                    }
                }
            }
        }
    }