Unity enables scene loading fade-in fade-out effect

Source: Internet
Author: User

In the project to use to load the scene when there is a gradual fade out of the effect, do a bit, to share with you

First, create two scenes of main and game scenes;

Next, create a FandeScene.cs script in the main scene, create a fade empty object, mount it, give a black picture, drag it into a preset, and drag it into the game scene.

using unityengine;using system.collections;public class fadescene :  monobehaviour {    public texture blacktexture;     private float alpha = 1.0f;    public float fadespeed =  0.2f;    private int fadedir = -1;    //  Use this for initialization    void Start  ()  {         }        // update  is called once per frame    void Update  ()  {         }    void ongui ()      {            alpha += fadedir  * fadespeed * time.deltatime;             gui.color = new color   (Gui.color .r ,gui.color .g ,gui.color .b,alpha);             gui. drawtexture  (new rect  (0,0,screen .width ,screen .height),  blackTexture);     }    public float beginfade (int direction)      {        fadeDir = direction;         return 1 / fadespeed;    }     void onlevelwasloaded ()     {         Debug.Log  ("Scene loading is complete! ");        beginfade  ( -1);       }}

Again, load the scene

CO preempted IEnumerator Fadeloadscene () {Float time = Gameobject.find ("Fade"). Getcomponent <FadeScene> ().        Beginfade (1);        Yield return new waitforseconds (time);    Scenemanager.loadsceneasync ("Game"); }

If you run this way, the fade-in effect will appear.

This article is from the "Unity_3d Technology discussion" blog, please be sure to keep this source http://myselfdream.blog.51cto.com/9944020/1828525

Unity enables scene loading fade-in fade-out effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.