I recently created a Unity tool to help automate some admin in my game (namely generating easy-to-read solutions to my puzzles), and as part of this I needed to get screenshots. This post details a quick and easy way to get a screenshot of your game and save it as an image file in your … Read moreEasy Screenshot in Unity
For my upcoming game, Mouse Dreams, I need to support gamepad input as well as keyboard and touch. It turns out this is not quite as simple as I first thought. The big issue with supporting UI with different input methods is how it will appear to the user. With touch or mouse input, the … Read moreSimple Script for Gamepad UI Navigation
Raycasting is one of those topics that everyone seems to struggle with at first, so here is a tutorial covering everything you need to know about raycasting in Unity. In this post I’ll explain what a raycast is, how to use a simple raycast, and point out a few potential problems and pitfalls people run … Read moreRaycasting Part 1: Everybody Loves Raycasting
You can use RequireComponent in your Unity scripts to save yourself some work and avoid errors. When your script requires a component, Unity will add a component of that type to your GameObject automatically when you add your script (if a component of the required type is not already there). You also cannot remove this … Read moreSave Time and Hassle with RequireComponent
Unity has events that tell your scripts when the mouse cursor hovers over an object and stops hovering over an object. This can be great for UI or for prompting the player that they they can interact with something. Note: this is an older post that uses the old Unity input system. This will still … Read moreInput: Detect Mouseover
Wherever Unity is discussed I see a mistake repeated by new Unity developers. It’s not a dumb or obvious mistake, but it can be a costly one. It’s the use of Unity’s ‘find’ functions to locate gameobjects and components inside update methods. Here’s the kind of thing I’m talking about: That line of code is … Read moreStop Looking, You Already Found It!
Drag-and-drop functionality is useful for many types of games – an inventory system in an RPG, dragging letters onto a word game board, etc. With a simple script you can add drag-and-drop functionality that will work with both mouse and touch input. This is also a perfect problem with which to demonstrate my technique for simplifying complex … Read moreDrag-and-Drop
Unity lacks a way to pass parameters to a new scene. If you want to send some game state data to the next level you have several options, such as PlayerPrefs or persistent classes, but they are not always elegant solutions. I decided to copy NavigationHelper from Windows Store apps. NavigationHelper allows you to send an object when navigating to a new … Read moreA Navigation Helper for Unity
Enemies are more challenging when they have some intelligence. A great start to building enemy AI is to grant enemies the power of sight! Sight is really a test that there is clear space between the enemy’s eyes and the player. With that knowledge it’s simple to work out a solution. You can download the sample project at the bottom of … Read moreGiving Enemies the Power of Sight!
Unity has a Debug class with some really useful functions for speeding up development, testing, and debugging. You probably already use Debug.Log() to add messages to the Console, such as keeping track of variables or notifying you of certain conditions: If you don’t use Debug.Log() you should! It will print anything you want into Unity’s … Read moreUsing the Debug Class