Unity: How to Exit a Game on Button Click

September 29, 2021 Pennywise

In Unity, you can programmatically quit a game in Unity by calling the Application.Quit() method. The code snippet below demonstrates how to exit a game when a button gets clicked: Note that your game will NOT…

Unity: DisplayDialogComplex Example

February 12, 2023 Pennywise

This practical article walks you through a complete example that demonstrates how to implement a complex dialog in Unity by using the built-in EditorUtility.DisplayDialogComplex static function. Without any further ado, let’s get our hands dirty. A…

C#: How to Convert a Numeric String to Int/Double

February 12, 2023 Pennywise

This article walks you through a few examples of converting a numeric string to an integer or a double in C#. Converting Numeric Strings to Integers Using Parse and TryParse Methods You can use the following…

Unity – How to Show a Confirmation Dialog

September 23, 2021 A Goodman

In order to show a confirmation dialog in Unity, you can use the EditorUtility.DisplayDialog() method. Before calling it, you need to add: Example The code: Screenshot: If you hit the “Yes” button, you will see: If…

Unity – How to Run a Function after a Delay

September 23, 2021 A Goodman

In order to execute a function after a delay in Unity, you can use Invoke(). If you want to invoke a function after a delay, then repeatedly call it, use InvokeRepeating(). Example: Output: Happy coding!

Unity – Programmatically Enable/Disable a Script Component

September 23, 2021 Pennywise

This short and straight-to-the-post post shows you how to programmatically enable or disable of C# file in Unity (not using the checkbox in the Inspector panel). Let’s say we have a C# file named Rocket that…

Unity – Programmatically Count the Scenes in Build Settings

September 22, 2021 Pennywise

In Unity, you can count the scenes that were added to Build Settings by using the following C# code: Example The function below will load the next scene when the index of the next scene is…

Unity – Light Becomes Darker when Load/Reload Scenes

September 22, 2021 A Goodman

When loading a new scene or reloading the current scene in Unity with the SceneManager.LoadScene() method, I notice an unexpected behavior: the environment and everything get darkened. That is not what I want so I try…

Unity – How to Change the Default Gravity

September 21, 2021 Pennywise

The steps listed below show you how to set your custom values for gravity in Unity (there is no difference between Windows and Mac). 1. Navigate to “Edit” > “Project Settings…” by using your mouse. 2….

C#: 2 Ways to Check if a String contains another String

September 20, 2021 Napoleon

This short and straight-to-the-point article shows you two different ways to whether a string contains another string in C Sharp. The first approach is case SENSITIVE while the second one is case INSENSITIVE. Using the Contains()…

Unity: Enable/Disable Gravity from C# Script

September 18, 2021 A Goodman

In Unity, you can programmatically enable or disable gravity for an object from your C# script as below: Example The following code will turn on gravity for an object 3 seconds after the game starts: You…

C#: Mixing Variables with String Literals

September 20, 2021 Napoleon

The three examples below show you how to use variables within string literals in C#. 1. Using the $ symbol Output: 2. Using + Operation Output: 3. Using String.Format Output: Happy coding!

1 2