C# 当启用false时,如何淡出ui文本?

C# 当启用false时,如何淡出ui文本?,c#,unity3d,C#,Unity3d,但这是丑陋的,它只是立即停止淡入淡出效应。我想以某种方式将其启用为false,但在此之前要完成当前的淡入淡出,因此启用为false的文本将平滑淡出,而不是突然停止淡入淡出效果。禁用它之前,请运行动画将其淡出。这个动画应该首先制作,或者你可以在网上找到 然后在将其设置为false之前运行动画 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; pu

但这是丑陋的,它只是立即停止淡入淡出效应。我想以某种方式将其启用为false,但在此之前要完成当前的淡入淡出,因此启用为false的文本将平滑淡出,而不是突然停止淡入淡出效果。

禁用它之前,请运行动画将其淡出。这个动画应该首先制作,或者你可以在网上找到

然后在将其设置为false之前运行动画

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SaveGameMessage : MonoBehaviour
{
    public Text text;
    public float speed;
    public bool startFading = false;
    public bool enableText = false;

    private Color textColor;

    private void Start()
    {
        text = GetComponent<Text>();
        textColor = text.color;
    }

    private void Update()
    {
        if (startFading == true)
        {
            if (enableText == true)
            {
                text.enabled = true;
            }

            textColor.a = (Mathf.Sin(Time.time * speed) + 1.0f) / 2.0f;
            text.color = textColor;
        }
        else
        {
            text.enabled = false;
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PlayingInGameScenesController : MonoBehaviour
{
    public CinemachineFreeLook[] freeLookcameras;
    public LockController lockController;
    public GameObject uiSceneText;
    public GameObject player;
    public float transitionSpeed = 5f;
    public float thresHold = 0.1f;
    public bool talkingProcess = true;
    public SaveGameMessage saveGameMessage;

    private bool newGame = true;

    private void Start()
    {
        
    }

    public void PlayingSceneInGame()
    {
        PlayingSceneStatesControls(true);
        StartCoroutine(ScenePlayingTime());
    }

    private void Update()
    {
        if (SceneManager.GetActiveScene().name != "Main Menu" && newGame == true)
        {
            PlayingSceneInGame();
            newGame = false;
        }
    }

    private void LateUpdate()
    {
       
    }

    private void PlayingSceneStatesControls(bool LockState)
    {
        lockController.LockControl(LockState);

        if (LockState == true)
        {
            uiSceneText.SetActive(true);
        }
        else
        {
            talkingProcess = false;
            uiSceneText.SetActive(false);
        }
    }

    IEnumerator ScenePlayingTime()
    {
        yield return new WaitForSeconds(10);

        PlayingSceneStatesControls(false);

        freeLookcameras[0].enabled = false;
        freeLookcameras[1].enabled = true;

        var brain = Camera.main.GetComponent<CinemachineBrain>().m_DefaultBlend.m_Time;

        saveGameMessage.enableText = true;
        saveGameMessage.startFading = true;

        player.GetComponent<Player>().SavePlayer();

        StartCoroutine(FakeSave());
    }

    IEnumerator FakeSave()
    {
        yield return new WaitForSeconds(7);

        saveGameMessage.startFading = false;
    }
}
text.enabled = false;