Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

Help with using OVRScreenFade to Fade Out

rcazzyrcazzy Posts: 16
Brain Burst
edited March 2016 in Unity Development
Hi guys,

I am awful at scripting and I'm trying to get an easy way to use fades for transitioning in scenes. I was wondering if anyone could help me out by showing me how I could reverse the OVRScreenFade to use as a fade and for it to be called (I assume as a Coroutine) from another script (say on a button press, the fade starts then a scene change after 4 seconds)? I'd really appreciate any help as I'm trying to finish a project wit this one issue.

Any help would be greatly appreciated. :D

Comments

  • petereptpeterept Posts: 170 Oculus Start Member
    Not using OVRScreenFade, but you could use the code I posted for creating splash screens fade in/out:

    http://talesfromtherift.com/vr-splash/

    Basically, this can be done easily with Canvas UI Group Panel set to Black that is parented to the camera when you want to fade in/out. Then use an animation curve to animate the transparency for the fade effect.

    HTH,

    Peter
    Check out my Unity VR development blog:
    http://talesfromtherift.com
    @peterept
  • vrdavebvrdaveb Posts: 1,596 Oculus Staff
    +1 for peterept's solution. If you really want to modify OVRScreenFade to support a fade-out, add something like this to it and then call StartFade() a couple of seconds before you switch scenes:
    public void StartFade()
    	{
    		StartCoroutine(FadeOut());
    	}
    
    	/// <summary>
    	/// Fades alpha from 0.0 to 1.0
    	/// </summary>
    	IEnumerator FadeOut()
    	{
    		float elapsedTime = 0.0f;
    		fadeMaterial.color = fadeColor;
    		Color color = fadeColor;
    		isFading = true;
    		while (elapsedTime < fadeTime)
    		{
    			yield return fadeInstruction;
    			elapsedTime += Time.deltaTime;
    			color.a = Mathf.Clamp01(elapsedTime / fadeTime);
    			fadeMaterial.color = color;
    		}
    		isFading = false;
    	}
    
  • rcazzyrcazzy Posts: 16
    Brain Burst
    Thank you both, both methods were interesting to test out.

    I went with the OVR Screen Fade method in this case just for ease for myself.
    I've found when I call the StartFade the screen will flash black for a brief second then the fade starts. Can you think of any reason why this would be occuring?
  • treytechtreytech Posts: 243
    Art3mis
    Try this (untested by me):
    IEnumerator FadeOut()
       {
          float elapsedTime = 0.0f;
          Color color = fadeColor;
          color.a = 0f;
          fadeMaterial.color = color;
          isFading = true;
          while (elapsedTime < fadeTime)
          {
             yield return fadeInstruction;
             elapsedTime += Time.deltaTime;
             color.a = Mathf.Clamp01(elapsedTime / fadeTime);
             fadeMaterial.color = color;
          }
          isFading = false;
       }
    
  • petereptpeterept Posts: 170 Oculus Start Member
    If it helps, attached is the script I used with animations to fade in, fade out and fade in-out.

    Drag the prefab as a child of your main camera.

    When you want to fade out, just use:
    Fader.Instance.FadeOut(() =>
    {
         Application.LoadLevel("Game");
    });
    
    Check out my Unity VR development blog:
    http://talesfromtherift.com
    @peterept
  • rcazzyrcazzy Posts: 16
    Brain Burst
    treytech wrote:
    Try this (untested by me):
    IEnumerator FadeOut()
       {
          float elapsedTime = 0.0f;
          Color color = fadeColor;
          color.a = 0f;
          fadeMaterial.color = color;
          isFading = true;
          while (elapsedTime < fadeTime)
          {
             yield return fadeInstruction;
             elapsedTime += Time.deltaTime;
             color.a = Mathf.Clamp01(elapsedTime / fadeTime);
             fadeMaterial.color = color;
          }
          isFading = false;
       }
    

    This works perfectly! Thank you so much! :D
    I'm going to be using your method for my next demo Peter, it looks really handy to use!
  • HannahTS95HannahTS95 Posts: 2
    NerveGear
    Is there a more recent solution to this problem? These answers don't seem to be compatible with OVRScreenFade anymore! Thank you!
  • AlanOTooleAlanOToole Posts: 135 Oculus Start Member
    Is there a more recent solution to this problem? These answers don't seem to be compatible with OVRScreenFade anymore! Thank you!
    Hey @HannahTS95

    Which version of the SDK are you using? There is now a native .FadeOut() function within OVRScreenFade.

    Check for this:
        /// <summary>
        /// Start a fade out
        /// </summary>
        public void FadeOut()
        {
            StartCoroutine(Fade(0,1));
        }

    Hope this helps!
  • HannahTS95HannahTS95 Posts: 2
    NerveGear
    edited October 2018
    Sorry, I am very new to coding in C#! Is there a way to call OVRScreenFade from another script so I can use .FadeOut() on a trigger?
Sign In or Register to comment.