コード例 #1
0
    IEnumerator DashToTarget(Vector3 targetPos)
    {
        dashing = true;

        // Set blur time -- Distance / Speed = Time
        quickBlur.StartCoroutine(quickBlur.FastBlur(Vector3.Distance(transform.position, targetPos) / 50.0f * Time.deltaTime));
        //Debug.Log((Vector3.Distance(transform.position, targetPos) / 50.0f * Time.deltaTime));

        // Move to point 0.8 distance error check to prevent over shooting the target
        while (Vector3.Distance(transform.position, targetPos) > 0.8f)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, 50.0f * Time.deltaTime);

            yield return(null);
        }

        // Re-position just in case -- Frame rate differences can result in player ending up not reaching or moving further
        transform.position = targetPos;

        dashing = false; // Reset boolean to allow for next dash
    }
コード例 #2
0
    IEnumerator SnapRotation(Quaternion targetRotation)
    {
        rotating = true;                                    // Prevent additional calls while rotating

        float delay = 0.5f;                                 // Delay Error check if angle value never reaches target value

        quickBlur.StartCoroutine(quickBlur.FastBlur(0.1f)); // Call Coroutine from QuickBlur script that blurs camera for set time and fades in/out the effect

        while (Quaternion.Angle(transform.rotation, targetRotation) > 0.5f && delay > 0.0f)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, 200.0f * Time.deltaTime); // Rotate towards target rotation at set speed, independent of frame rate using DeltaTime

            delay -= 1.0f * Time.deltaTime;                                                                             // Error check delay

            yield return(null);                                                                                         // Return function for this frame to prevent freezing the entire program until While loop is complete -- restart from While loop next frame
        }

        rotating = false;
    }