コード例 #1
0
    public override void GenerateItems(Pipe pipe)
    {
        float start     = Random.Range(0, pipe.pipeSegmentCount) + 0.5f;
        float direction = Random.value < 0.5f ? 1f : -1f;

        float angleStep = pipe.CurveAngle / pipe.CurveSegmentCount;

        for (int i = 0; i < pipe.CurveSegmentCount; i++)
        {
            PipeItem item         = Instantiate <PipeItem>(itemPrefabs[Random.Range(0, itemPrefabs.Length)]);
            float    pipeRotation = (start + i * direction) * 360f / pipe.pipeSegmentCount;
            item.Position(pipe, i * angleStep, pipeRotation);
        }
    }
コード例 #2
0
    public void Generate(bool with_obstacles, bool with_egg)
    {
        curveRadius  = Random.Range(minCurveRadius, maxCurveRadius);
        curveSegment = Random.Range(minCurveSegment, maxCurveSegment + 1);

        mesh.Clear();

        SetupVertices();
        SetupUV();
        SetupTriangles();

        mesh.RecalculateNormals();
        mesh.RecalculateBounds();

        meshCollider.sharedMesh = mesh;
        //meshCollider.convex = true;

        for (int i = 0; i < transform.childCount; i++)
        {
            Destroy(transform.GetChild(i).gameObject);
        }


        if (with_obstacles && ciliaGenerators.Length > 0)
        {
            if (ciliaGenerators.Length > 0)
            {
                ciliaGenerators[Random.Range(0, ciliaGenerators.Length)].GenerateItem(this);
            }

            if (obstacleGenerators.Length > 0)
            {
                obstacleGenerators[Random.Range(0, obstacleGenerators.Length)].GenerateItem(this);
            }
        }

        if (with_egg)
        {
            float    angleStep = curveAngle / curveSegment;
            PipeItem egg       = Instantiate(ovum);
            int      segment   = Random.Range(0, curveSegment);
            egg.Position(this, segment * angleStep, new Vector3(360f / pipeSegment, 0f, 0f));
        }
    }