Friday, 23 February 2018

How to overlay a firework show before your 2D GUI in Unity3D

You may want to have a firework show in your 2D game when your user wins. It is pretty easy with Unity3D.

Just add a new camera to your existing scene. Set "Clear Flags" to "Don't clear", and set "Depth" to a greater value than that of your 2D GUI's camera. Then what ever this camera sees will be displayed over your 2D GUI.

Then add your firework prefab as child of your new camera, and adjust its position so that it looks good in your camera. And that's it.

Wednesday, 14 February 2018

NullReferenceException with unity3d on iOS

To debug NullReferenceException on iOS, write lots of Debug.Log for objects, and in build settings enable development build and script debugging.

This could happen if GameObject.FindGameObjectWithTag is used in Awake or Start because the object may not be created when Awake or Start is executed. The issue may not show up in editor since in editor the objects may already be there but they may not be created when running the app on iOS. One workaround is to do it at point of usage when the object has been created.