Esempio n. 1
0
    IEnumerator lerpMagicLine(float speed, talisman target)
    {
        float         startTime    = Time.time;
        GameObject    line         = Instantiate(magicLine, transform.position, transform.rotation, null);
        TrailRenderer trail        = line.GetComponent <TrailRenderer>();
        float         delay        = trail.time;
        bool          countingDown = false;

        while (delay > 0)
        {
            if (!countingDown)
            {
                if (Vector3.SqrMagnitude(target.transform.position - line.transform.position) < nearbyDistance)
                {
                    countingDown = true;
                    target.ReceivePing();
                }
            }
            if (countingDown)
            {
                delay     -= Time.deltaTime * 5;
                trail.time = delay;
            }
            Vector3 position = Vector3.MoveTowards(line.transform.position, target.transform.position, speed * Time.deltaTime);
            line.transform.position = position;
            yield return(null);
        }
    }
Esempio n. 2
0
    IEnumerator lerpMagicLineTimed(float time, talisman target)
    {
        float         progress     = 0;
        GameObject    line         = Instantiate(magicLine, transform.position, transform.rotation, null);
        TrailRenderer trail        = line.GetComponent <TrailRenderer>();
        float         delay        = trail.time;
        bool          countingDown = false;

        while (delay > 0)          //while the line has a reason to maintain its position
        {
            if (!countingDown)     //if the line has not yet reached the target talisman
            {
                if (progress >= 1) //if the line actually has though
                {
                    progress     = 1;
                    countingDown = true;  //start retracting the tail of the line
                    target.ReceivePing(); //tell the target that we made it
                }
                else //otherwise keep increasing progress until it > 1
                {
                    progress += Time.deltaTime / time;
                }
            }

            if (countingDown) //if we are retracting the tail of the line
            {
                delay     -= Time.deltaTime * 5;
                trail.time = delay;
                if (trail.time <= 0)
                {
                    Destroy(trail.gameObject);
                }
            }

            Vector3 position = Vector3.Lerp(transform.position, target.transform.position, progress);
            line.transform.position = position;
            yield return(null);
        }
    }