Beispiel #1
0
    // Begin teleport fade effect, then find a viable teleport spot, then teleport and reverse the teleport fade
    private IEnumerator TeleportFade()
    {
        dissolveStep = -1;

        dissolveGoal = 1;


        foreach (MeshRenderer m in carMeshes)
        {
            // Get the current value of the material properties in the renderer.
            m.GetPropertyBlock(_propBlock);

            // Assign our new value.
            _propBlock.SetFloat("_TeleportEnable", 1);

            // Apply the edited values to the renderer.
            m.SetPropertyBlock(_propBlock);
        }

        // Setting network to allow teleporting so objects don't smoothly move between two points
        networkCharacter.SetTeleporting(true);

        // Start teleport dissolve until invisible
        while (dissolveStep < 1)
        {
            lastStep      = dissolveStep;
            dissolveStep  = Mathf.MoveTowards(dissolveStep, dissolveGoal, 3f * Time.deltaTime);
            dissolveDelta = dissolveStep - lastStep;

            foreach (MeshRenderer m in carMeshes)
            {
                // Get the current value of the material properties in the renderer.
                m.GetPropertyBlock(_propBlock);

                // Assign our new value.
                _propBlock.SetFloat("_DissolveStep", dissolveStep);

                // Apply the edited values to the renderer.
                m.SetPropertyBlock(_propBlock);
            }


            networkCharacter.SetDissolve(dissolveStep, dissolveDelta);

            yield return(new WaitForFixedUpdate());
        }

        // Get the furthest available teleport spot
        teleportPosition = FindTeleportSpot();

        Debug.DrawLine(carCenter.position, teleportPosition, Color.blue);

        // Teleport the player by giving them new position
        this.transform.position = teleportPosition;

        dissolveStep = 1;

        dissolveGoal = -1;

        // Shoot out teleport particles on every other players local clients
        networkCharacter.SetTeleportParticles();
        teleportParticles.Play();


        // Reverse teleport dissolve until visible
        while (dissolveStep > -1)
        {
            lastStep      = dissolveStep;
            dissolveStep  = Mathf.MoveTowards(dissolveStep, dissolveGoal, 3.5f * Time.deltaTime);
            dissolveDelta = dissolveStep - lastStep;


            foreach (MeshRenderer m in carMeshes)
            {
                // Get the current value of the material properties in the renderer.
                m.GetPropertyBlock(_propBlock);

                // Assign our new value.
                _propBlock.SetFloat("_DissolveStep", dissolveStep);

                // Apply the edited values to the renderer.
                m.SetPropertyBlock(_propBlock);
            }

            networkCharacter.SetDissolve(dissolveStep, dissolveDelta);

            yield return(new WaitForFixedUpdate());
        }

        networkCharacter.SetDissolve(-1, 0);

        networkCharacter.SetTeleporting(false);

        networkCharacter.EndDissolving();

        // Turn off teleport enable so dithering can continue normally
        foreach (MeshRenderer m in carMeshes)
        {
            // Get the current value of the material properties in the renderer.
            m.GetPropertyBlock(_propBlock);

            // Assign our new value.
            _propBlock.SetFloat("_TeleportEnable", 0);

            // Apply the edited values to the renderer.
            m.SetPropertyBlock(_propBlock);
        }

        teleportParticles.Stop();
    }