Ejemplo n.º 1
0
    // Update is called once per frame
    public void AddObject(Transform parent)
    {
        float spacing = SpacingCoef + Random.Range(0, 1f);
        float length  = 1 + StretchCoef * Random.Range(0, 1f);

        float      r  = Random.Range(-20f, 20f);
        float      rz = spacing * Random.Range(0f, 1f);
        SplineLine sl = Instantiate(ss, lastPosition.withY(lastPosition.y - rz), Quaternion.Euler(0f, (360f / 4f) * (count % 4) + r, 0f), parent).GetComponent <SplineLine>();

        sl.gameObject.SetActive(true);
        sl.gameObject.name = "Spline";
        lastPosition       = sl.Init(100, length);
        count++;

        //every 8 lines, we add a platform,
        if (count % 5 == 4 && rz > 4f)
        {
            GameObject pl            = Instantiate(platform, sl.endPos.withY(sl.endPos.y + 2f * spacing), Quaternion.identity, sl.gameObject.transform);
            SplineLine sls           = Instantiate(ss, sl.endPos, Quaternion.identity, pl.transform).GetComponent <SplineLine>();
            Vector3[]  splineTargets = new Vector3[3];
            splineTargets[0] = sl.attachPos;
            splineTargets[1] = 0.5f * (sl.attachPos + pl.transform.position) + 3f * length * sl.transform.forward;
            splineTargets[2] = pl.transform.position;
            sls.InitSimple(splineTargets);
            sls.line.widthMultiplier *= 0.5f;
            sls.gameObject.SetActive(true);
            pl.SetActive(true);
        }
        if (count % 30 == 0)
        {
            Debug.Log(sl.endPos.y / Mathf.Floor(count / 30));
        }
    }