Пример #1
0
    void Start()
    {
        river = FindObjectOfType <River>();

        var y = transform.position.y;
        var x = Random.Range(river.GetBank(y, true) + radius, river.GetBank(y, false) - radius);

        transform.position = new Vector3(x, y, transform.position.z);

        lines             = new LineRenderer[lineCount];
        lineTimeOffsets   = new float[lineCount];
        lineRadiusOffsets = new float[lineCount];

        for (int i = 0; i < lineCount; i++)
        {
            var lineObj = new GameObject();
            lineObj.transform.position = transform.position;
            lineObj.transform.SetParent(transform);
            lines[i]               = lineObj.AddComponent <LineRenderer>();
            lines[i].startWidth    = 1f / 16f;
            lines[i].endWidth      = 1f / 16f;
            lines[i].useWorldSpace = false;
            lines[i].material      = lineMaterial;
            lineTimeOffsets[i]     = Random.value;
            lineRadiusOffsets[i]   = Random.value;
        }
    }
Пример #2
0
    void Update()
    {
        var camExtent = Camera.main.orthographicSize;
        var camBottom = cameraPosition.transform.position.y - camExtent;

        if (transform.position.y < camBottom - 2f)
        {
            var y = transform.position.y + camExtent * 2f + 4f;
            var x = Random.Range(river.GetBank(y, true) + radius, river.GetBank(y, false) - radius);
            transform.position = new Vector2(x, y);
        }

        deltaTime += Time.deltaTime;
        UpdateLines();
    }
Пример #3
0
    void Update()
    {
        var current = river.GetCurrent(transform.position.y);

        transform.position += (Vector3)current * 2f * Time.deltaTime;

        var cameraSize   = Camera.main.orthographicSize;
        var cameraTop    = cameraPosition.position.y + cameraSize;
        var cameraBottom = cameraPosition.position.y - cameraSize;

        if (transform.position.y > cameraTop + 2f)
        {
            var y = cameraBottom;
            var x = Random.Range(river.GetBank(y, true), river.GetBank(y, false));
            MoveTo(new Vector3(x, y, transform.position.z));
        }
        else if (transform.position.y < cameraBottom - 2f)
        {
            var y = cameraTop;
            var x = Random.Range(river.GetBank(y, true), river.GetBank(y, false));
            MoveTo(new Vector3(x, y, transform.position.z));
        }
    }