Transition fast&slow between gameObject

For example I have 2 buttons on the screen.

If it’s the first time I’ve to be displayed, than just display me.(Fade me in && setactive(true))
If not the first time, Fade me out, make me active(false), display another object(fade it in - need to assign its fade to zero first), and make it active.

Well, when transitioning slow(i.e. letting the fade in finish) between the button clicks, it works fine.

PROBLEM: When clicking really fast between the buttons sometimes both the models are disabled.

I’m already working on it for hours to see where the bug is, I’d love to get your opinion about it.

UIManager code:

#region Transitions
private bool _isTransitioningIn = false;
private GameObject _currentTransitionInObject = null;
private GameObject _lastCompletedTransitionInObject;
public void DisplayDish(GameObject go) {
    Debug.Assert (!(_isTransitioningIn ^ _currentTransitionInObject));
    //_lastCompletedTransitionInObject.gameObject.SetActive (true);
    if (_isTransitioningIn) {
        HideDish (_currentTransitionInObject, TransitionManager.TransitionSpeed.FAST);
    }
    else {
        if (_lastCompletedTransitionInObject) {
            HideDish (_lastCompletedTransitionInObject);
        }
    }
    _isTransitioningIn = true;
    _currentTransitionInObject = go.gameObject;
    _transitionManager.TransitionIn (go.gameObject, TransitionManager.TransitionSpeed.NORMAL, (__go) => {
        if (_currentTransitionInObject == __go) {
            _isTransitioningIn = false;
            _currentTransitionInObject = null;
            _lastCompletedTransitionInObject = __go;
        }
    });
}
public void HideDish(GameObject go) {
    HideDish (go, TransitionManager.TransitionSpeed.NORMAL);
}
private void HideDish(GameObject transitionGo, TransitionManager.TransitionSpeed transitionSpeed) {
    _transitionManager.TransitionOut (transitionGo, transitionSpeed, (go) => {
        go.SetActive(false);
        Debug.Log("RESTAR | Hiding: " + go);
    });
}
#endregion

And the Transition Manager:

public class TransitionManager
{
    private static float FAST_FADE_IN_TIME = 0.1f;
    private static float NORMAL_FADE_IN_TIME = 1f;

    private static float FAST_FADE_OUT_TIME = 0.1f;
    private static float NORMAL_FADE_OUT_TIME = 1f;

    public enum TransitionSpeed
    {
        FAST,
        NORMAL
    }

    public TransitionManager ()
    {
    }

    public void TransitionIn(GameObject go, TransitionSpeed transitionSpeed, Action<GameObject> callback)
    {
        var renderer = go.GetComponent<Renderer> ();
        if (renderer == null) {
            renderer = go.GetComponentInChildren<Renderer> (true);
        }

        go.SetActive (true);

        float transitionSpeedSeconds = transitionSpeed == TransitionSpeed.FAST ?
            FAST_FADE_IN_TIME :
            NORMAL_FADE_IN_TIME;

        //Init object's alpha to zero
        renderer.material.color = new Color (1, 1, 1, 0);

        //Kill the current available DO objects - for fading purposes
        renderer.material.DOKill (true);

        //Fade in
        renderer.material.DOFade (1.0f, transitionSpeedSeconds).OnComplete (() => {
            callback (go);
        });
    }

    public void TransitionOut(GameObject go, TransitionSpeed transitionSpeed, Action<GameObject> callback)
    {
        var renderer = go.GetComponent<Renderer> ();
        if (renderer == null) {
            renderer = go.GetComponentInChildren<Renderer> (true);
        }

        float transitionSpeedSeconds = transitionSpeed == TransitionSpeed.FAST ?
            FAST_FADE_OUT_TIME :
            NORMAL_FADE_OUT_TIME;

        //Kill the current available DO objects - for fading purposes
        renderer.material.DOKill (true);

        //Fade out
        renderer.material.DOFade (0.0f, transitionSpeedSeconds).OnComplete (() => {
            callback (go);
        });
    }
}

I understood your question but i didn’t fully understand your script .But i had a pretty similar problem. I was Color.lerp for a cube when i clicked it. As i had several cubes, if i clicked on another cube while the first cube’s color was being changed the first cube’s color remained in between the 2 colors and the 2nd cube’s color started lerping. There was a simple fix to this problem. I just needed to create a local variable for storing the information about the index number of the cube. After doing that, if i clicked on 2nd cube while the first one is still lerping,the first one’s color jumps to the final color and doesn’t stop in between. Check the 5th post here. That may be able to help you.

Solution:

public void TransitionIn(GameObject go, TransitionSpeed transitionSpeed, Action<GameObject> callback) 
{
	var renderer = go.GetComponent<Renderer> ();
	if (renderer == null) {
		renderer = go.GetComponentInChildren<Renderer> (true);
	}
	Debug.Log ("3");
	go.SetActive (true);

	float transitionSpeedSeconds = transitionSpeed == TransitionSpeed.FAST ?
		FAST_FADE_IN_TIME :
		NORMAL_FADE_IN_TIME;

	//Init object's alpha to zero
	renderer.material.color = new Color (1, 1, 1, 0);

	//Kill the current available DO objects - for fading purposes
	renderer.material.DOKill (true);

	//Fade in
	renderer.material.DOFade (1.0f, transitionSpeedSeconds).OnComplete (() => {
		callback (go);
	});
	go.SetActive (true);
}