Reply To: Unity 5 support

Home Forums Books Mastering Unity 2D Game Development Unity 5 support Reply To: Unity 5 support

#7972

The road continues, with each new version of Unity 5, it introduces even more change, with 5.1 we can see there are a few more “improvements” or “Obsolete  Notices” as the busy train keeps moving.

As I intend to ensure readers always have the latest information, I keep updating this thread, as of 5.1, Unity have put on notice the ability to create simple shaders in code which the book uses as part of the “FadeInOutManager” in chapter x.

In the chapter we currently have:

fadeMaterial = new Material(“Shader \”Plane/No zTest\” {” +
“SubShader { Pass { ” +
”    Blend SrcAlpha OneMinusSrcAlpha ” +
”    ZWrite Off Cull Off Fog { Mode Off } ” +
”    BindChannels {” +
”      Bind \”color\”, color }” +
“} } }”);

Declaring a shader like this is no longer (or very shortly won’t be) supported, so we have to create the shader in a shader file and then reference to it in code.

So here are the steps to update:

  1. Create a new folder in the assets project called “Shaders” (we didn’t use shaders specifically in the book, so this is new)
  2. Select the shaders folder and right-click in the project window and select “Create -> Shader“, name it “FadeInOutShader
  3. Open the new shader in your code editor by double clicking on it and replace it’s contents with the following:
    (P.S. if you haven’t already, have you checked out Microsofts new multi-platform lightweight code editor which can be used with Unity? – http://wp.me/p3o0M2-1VH )

    Shader “Custom/FadeInOutShader” { SubShader { Pass { Blend SrcAlpha OneMinusSrcAlpha ZWrite Off Cull Off Fog { Mode Off } BindChannels { Bind “color”, color } } } }

  4. Save the shader and return to Unity and open up the “Scripts\FadeInOutManager.cs” script
  5. Replace lines 26 – 32 (the code shown earlier) with the following

        Shader shader = Shader.Find(“Custom/FadeInOutShader”);        fadeMaterial = new Material(shader);

  6. Save and run.

All this change does is to move the code generated shader in to an actual shader definition file (removing all the funky stuff we add in the code as well, including escape characters), then we reference that shader in our code and use it for our fading material.  The shader could probably be improved for more effect but that was well outside the scope for the title.

Any more queries or suggestions, just let me know.

 

 

Simon (Darkside) Jackson
@SimonDarksideJ