Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (brotherLerp != speed.GetBrotherLerp())
        {
            brotherLerp = speed.GetBrotherLerp();
            ResetLerp(brotherLerp);
        }

        if (vacuumLerp != speed.GetVacuumLerp())
        {
            vacuumLerp = speed.GetVacuumLerp();
            ResetLerp(vacuumLerp);
        }

        // add to the current time in the lerp
        currentLerpTime += Time.deltaTime;

        // make sure the current time stays within the designated time
        if (currentLerpTime > targetlerpTime)
        {
            currentLerpTime = targetlerpTime;
        }

        if (!isVacuum)
        {
            if (transform.position != brotherPosition)
            {
                // use time elapsed as a percentage of the target time as speed
                float travelPercentCompleted = currentLerpTime / targetlerpTime;

                // lerp the thing
                transform.position = Vector3.Lerp(startPosition, brotherPosition, travelPercentCompleted);
            }
        }
        else
        {
            playerPosition = player.transform.position;

            if (transform.position != playerPosition)
            {
                // use time elapsed as a percentage of the target time as speed
                float travelPercentCompleted = currentLerpTime / targetlerpTime;

                // lerp the thing
                transform.position = Vector3.Lerp(startPosition, playerPosition, travelPercentCompleted);
            }
        }
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        scoreboard = GameObject.FindGameObjectWithTag("Score").GetComponent <Score>();
        speed      = GameObject.FindGameObjectWithTag("Speed").GetComponent <SpeedManager>();

        player = GameObject.FindGameObjectWithTag("Player");

        brotherLerp = speed.GetBrotherLerp();
        vacuumLerp  = speed.GetVacuumLerp();

        targetlerpTime = brotherLerp;

        startPosition   = transform.position;
        brotherPosition = GameObject.FindGameObjectWithTag("Brother").transform.position;
    }