I constantly run across a variety of tips and tricks, whether from reddit, people on Patreon I follow, reading books, or just various stuff I discover myself. I started this page to track those tips and tricks and locate them all in a single place for me, hopefully you will get some use from them as well.

When a group of tips and tricks grows big enough I will relocate them to a separate page to make it easier to focus on them.

Table of Contents


back to table of contents


  • What’s New in C# 8.0 (Preview as 24 Apr 2019) – MS docs site
  • Use variable formatting in a string interpolation
    • _var.Text = $"{num.ToString(_format)} text goes here.";
  • Use fixed formatting in string interpolation
    • _var.Text = $"{num:N0} text goes here.";

back to table of contents

Switch with Pattern Matching Cases

Beginning with C# v7 you can use pattern matching in switch cases. If you use Unity 2018.3 or later (or an earlier version that allows .NET v4.0) you can do something like the code below.

void OnCollisionEnter(Collision other)
  // Detect and handle collisions
  switch (other.gameObject.name)
    case string a when a.Contains("Wall"):
      bouncePos = transform.position;
      bounce = true;
    case string a when a.Contains("Door"):
      bouncePos = transform.position;
      bounce = true;
    case string a when a.Contains("Stairs"):
      distanceToMove = 0.0f;  // Disable moving before changing levels
      distanceToMove = 4.0f;  // Enable moving after changing levels
    case null:
      new System.ArgumentNullException(nameof(other));

back to table of contents

itch.io Widget

  • The itch.io game widget requires an iframe, which is blocked in some versions of WordPress.com, you need a business subscription or higher to use iframes.
    • I created a workaround by taking a screenshot of the widget, uploading the picture, and when I use put it on a page I link it to the game page.


back to table of contents


back to table of contents

Adding External DLLs to Unity

I had a case where I wanted to use the System.Numerics namespace, however, it is not part of the normal Unity NET. I added a ‘mcs.rsp’ file (which is a text file) to the Assets folder and then added the follow line to it. (Current as of late 2018, the folder may change over time.)

-r:"C:/Program Files/Unity/Editor/Data/MonoBleedingEdge/lib/mono/4.5/System.Numerics.dll"

Then I went back to Unity and clicked the Assets menu, then Refresh to get Unity to recompile the code and include the reference.

⚠️NOTE: This caused a conflict with various Vector classes. To work around this I created a using alias directive, i.e., using Num = System.Numerics.

⚠️NOTE: The file name depends on the .NET version targeted, ‘mcs’ for .NET v3.5 (deprecated) and ‘csc’ for .NET v4. See the bottom of the Platform Dependent Compilation page. To see the ‘mcs’ help navigate to a folder similar to “C:\Program Files\Unity\Hub\Editor\2018.3.0f2\Editor\Data\MonoBleedingEdge\lib\mono\4.5” (adjusted for version), open a command window, and type ‘mcs -help’. I assume csc and mcs have the same options.

mcs Options

back to table of contents

Folder Structure

Create a folder like ‘_Game’, in the ‘Assets’ folder, so it sits at the top of the folder structure. All the downloaded assets can set in the main ‘Assets’ folder and I can always find my game assets. Don’t move assets that are generated, e.g., materials generated from a model.
Below I listed out the current folder structure I use. I only create a folder when I need it so as to not clutter my folders. The folder structure is adapted from a variety of sources.

Current as of 24 April 2019.

  • Animations
    • Clips
    • Controllers
  • Audio
    • Enemy
    • FX
    • Music
    • Player
  • Fonts
  • Graphics
  • Materials
  • Models
  • Physical Materials
  • Plugins
  • Prefabs
    • Characters
    • Environment
    • FX
    • Props
    • UI
  • Resources
  • Scenes
  • Scripts
    • {Folders as needed}
  • Shaders
  • Sprites
    • Characters
    • Environment
    • FX
    • Props
    • UI
  • Textures

back to table of contents

Scene Hierarchy Structure

Reset all empty GameObjects to the following values: transform (0, 0, 0); rotation (0, 0, 0); scale (1, 1, 1). For empty GameObjects that hold scripts use a @ prefix, e.g., @Cheats. When you instantiate an object during runtime put it in ‘_Dynamic’.

Create empty GameObjects for each of these sections. My current practice is to put as much as I can as a child object so that I collapse entire sections and focus on just what I need to see. I got this structure from The Knights of Unity.

Current as of 24 April 2019.

  • Management
  • GUI
  • Cameras
  • Lights
  • World
    • Terrain
    • Props
  • _Dynamic

back to table of contents

VS Code

back to table of contents

Send a Missive

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.