private void GrowLength()
    {
        WormSegment current = this.GetComponent <WormHead> ().Behind;

        while (current.Behind != null)
        {
            current = current.Behind;
        }
        current.ExtendWorm(1, 2);
    }
Ejemplo n.º 2
0
    public void ExtendWorm(int currentSize, int maxSize)
    {
        if (currentSize >= maxSize)
        {
            this.transform.localScale /= 2;            // tail will look half the size
            return;
        }
        WormSegment newSegment = Instantiate(wormSegmentPrefab, transform.parent);

        newSegment.name = "worm-segment-" + currentSize;
        newSegment.SetSegmentAhead(this);
        segmentBehind = newSegment;
        if (!segmentAhead)
        {
            newSegment.transform.localPosition = 2 * wormSpread * (transform.position - Vector3.up).normalized;
        }
        else
        {
            newSegment.transform.localPosition = wormSpread * (transform.position - segmentAhead.transform.position).normalized;
            newSegment.transform.localScale    = -segmentAhead.transform.localScale;          // each segment is a flip of the previous
        }
        newSegment.ExtendWorm(currentSize + 1, maxSize);
    }