Unity For Dummies

Its me, I’m the dummy.

I wanted to get out of Ren’Py for game making. As much as I love it, I’d like to create some narrative based games that don’t rely so heavily on the visual novel format. I chose Unity with C# as I’ve been wanting to learn a little more code and C# is a pretty good skill to have on hand for my technical art day job too!

The game I had in mind revolves around using random cards to build up a spooky haunted house exploration story, much like World of Horror or Betrayal at House on the Hill. I’ve got some game design stuff that I’ll share in another post.

I sort of rushed right ahead into this, then realised that Unity doesn’t work in the way I’m used to with regard to classes and data storage. (I’ve used it professionally, but only as an artist.) Being in python mostly I’m used to just defining a bunch of classes and functions and using them whenever and wherever I want to. Unity is a lot more strict on what types of classes can be used where and how things should be structured.

The video below was a nice intro to how classes work in Unity – super simple stuff, but exactly what I needed. It shows how to make a constructor using the same name as the class, which was one of the things I was unsure about as I’m used to Python’s __init__ function.

My first task was to populate some UI text using predefined card objects, and I needed a card class, a dictionary of all existing cards and something to handle populating the text.

At first, I made three classes, all as monobehaviours, as is the default, and everything broke! Monobehaviour classes are designed to be attached to GameObjects, not to be created inside other scripts. As an alternative to monobehaviours, you can use a ScriptableObject – a data container that stores unchanging data, create your own super class or not have it derive from anything. For data with no behaviour, a struct is also an option.

In the end, I made a struct to hold the card data, a ScriptableObject to hold the dictionary of cards, that also contained adding and removal functionality, and a Monobehaviour attached to the main canvas that handed picking a random element from the dictionary and populating the UI fields with it.

Created with Coggle.it

The next step with this is to work out how to create card objects outside of runtime, and how to populate the dictionary with these. It looks like ScriptableObjects can be created as .asset files and used in editor, so I’m going to look into this as an option. Ideally, I’d love a tool that is aimed at narrative designers that lets them not only fill in the content, but create choices and localise text – that’s getting well ahead of myself though!

Leave a Reply

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