Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当重新启动协同程序时,如何确保对话不会再次播放?_C#_Unity3d - Fatal编程技术网

C# 当重新启动协同程序时,如何确保对话不会再次播放?

C# 当重新启动协同程序时,如何确保对话不会再次播放?,c#,unity3d,C#,Unity3d,在DepthOfField脚本中,我使用一个公共静态标志来检查协程何时完成 此标志: public bool dephOfFieldFinished = false; 脚本的其余部分:我正在使用后处理和聚焦来创建一些模糊效果 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.PostProcessing; public class DepthOfF

在DepthOfField脚本中,我使用一个公共静态标志来检查协程何时完成

此标志:

public bool dephOfFieldFinished = false;
脚本的其余部分:我正在使用后处理和聚焦来创建一些模糊效果

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;


public class DepthOfField : MonoBehaviour
{
    public UnityEngine.GameObject player;
    public PostProcessingProfile postProcessingProfile;
    public bool dephOfFieldFinished = false;
    public LockSystem playerLockMode; 

    private Animator playerAnimator;
    private float clipLength;
    private Coroutine depthOfFieldRoutineRef;
    private DepthOfFieldModel.Settings depthOfField;
    private DepthField state;

    void Start()
    {
        if (depthOfFieldRoutineRef != null)
        {
            StopCoroutine(depthOfFieldRoutineRef);
        }

        playerAnimator = player.GetComponent<Animator>();

        AnimationClip[] clips = playerAnimator.runtimeAnimatorController.animationClips;
        foreach (AnimationClip clip in clips)
        {
            clipLength = clip.length;
        }

        DepthOfFieldInit(300, clipLength);

        state = new DepthField();
    }

    public void DepthOfFieldInit(float focalLength, float duration)
    {
        depthOfField = postProcessingProfile.depthOfField.settings;
        depthOfField.focalLength = focalLength;
        StartCoroutine(changeValueOverTime(depthOfField.focalLength, 1, duration));
        postProcessingProfile.depthOfField.settings = depthOfField;
    }

    public IEnumerator changeValueOverTime(float fromVal, float toVal, float duration)
    {
        playerLockMode.PlayerLockState(true, true);

        float counter = 0f;

        while (counter < duration)
        {
            var dof = postProcessingProfile.depthOfField.settings;

            counter += Time.deltaTime;

            float val = Mathf.Lerp(fromVal, toVal, counter / duration);

            dof.focalLength = val;
            postProcessingProfile.depthOfField.settings = dof;

            state.counterDuration = counter;
            state.focalLength = val;

            yield return null;
        }

        playerAnimator.enabled = false;
        dephOfFieldFinished = true;
        depthOfFieldRoutineRef = null;
    }

    public struct DepthField
    {
        public float focalLength;
        public float counterDuration;
    }

    public void Save()
    {

    }

    public void Load()
    {

    }
}
然后我在另一个场景中添加了一个带有更新的脚本,这个方法返回到菜单

private void Update()
    {
        if (InMainMenu == false)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                InMainMenu = true;
                BackToMainMenu();
            }
        }
    }
以及:

如何使用相同的协同程序在escape键上创建模糊效果,而不重新开始对话


也许我不应该使用这个公共静态标志来检查协同程序是否已经完成,并以其他方式进行检查?也许我应该在DepthOfField中添加另一个协同程序,只是为了使用escape键?

在您的情况下,对话仅基于景深已完成这一事实开始。据我所知,你需要在满足其他条件时启动它。因此,您还应该检查其他条件,而不仅仅是已完成的景深。

if(dephOfField.dephoffieldfieldFinished==true&&!conversationcomplete)。。。。
private void Update()
    {
        if (InMainMenu == false)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                InMainMenu = true;
                BackToMainMenu();
            }
        }
    }
public static void BackToMainMenu()
    {
        var depthOfField = GameObject.Find("Player Camera").GetComponent<DepthOfField>();
        depthOfField.DepthOfFieldInit(300, 3);
        Cursor.lockState = CursorLockMode.Confined;
        Time.timeScale = 0f;
        SceneManager.LoadScene(MainMenuScene.name, LoadSceneMode.Additive);
        InMainMenu = true;
    }
if (dephOfField.dephOfFieldFinished == true)