Exemple #1
0
    private void GenerateTrees(ForestLayer layer)
    {
        layer.startpos = transform.position.x;
        layer.length   = bc.bounds.size.x;

        for (float x = (transform.position.x - 2 * (bc.bounds.size.x)); x < (transform.position.x + 2 * (bc.bounds.size.x)); x += layer.interval)
        {
            float value = Mathf.PerlinNoise((transform.position.x + x) / 10, layer.layerY);

            if (value > 1 - layer.density)
            {
                GameObject instance = GameObject.Instantiate(layer.frontTreePrefabs[Random.Range(0, layer.frontTreePrefabs.Length)]);
                instance.transform.localPosition = new Vector2(x + Random.Range(-layer.interval, layer.interval), layer.layerY + Random.Range(-.18f, .18f));
                instance.transform.localScale    = new Vector3(Random.Range(.95f, 1.05f), Random.Range(.95f, 1.05f), 1);
                instance.transform.parent        = layer.parent;
                BoxCollider2D  tc  = instance.GetComponent <BoxCollider2D>();
                SpriteRenderer tsr = instance.GetComponent <SpriteRenderer>();
                tsr.color        = layer.layerColor;
                tsr.sortingOrder = 3 - layer.parallaxLayer;
                objects.Add(instance);
                float ySize = tc.bounds.size.y / 2;


                if (!layer.keepTriggers)
                {
                    GameObject.Destroy(tc);
                }
            }
        }
    }
Exemple #2
0
    private void ParallaxLayer(ForestLayer layer, float delta)
    {
        Vector3 newPos = layer.parent.localPosition;

        newPos.x += delta * layer.parallaxEffect;
        layer.parent.localPosition = newPos;
    }