Kinda Code
Home/C Sharp

C Sharp

Unity: DisplayDialogComplex Example

Unity: DisplayDialogComplex Example

Updated: Feb 12, 2023
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......
C#: How to Convert a Numeric String to Int/Double

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

Updated: Feb 12, 2023
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 methods to parse......
Unity: How to Exit a Game on Button Click

Unity: How to Exit a Game on Button Click

Updated: Sep 29, 2021
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: using System.Collections; using......
Unity – How to Show a Confirmation Dialog

Unity – How to Show a Confirmation Dialog

Updated: Sep 23, 2021
In order to show a confirmation dialog in Unity, you can use the EditorUtility.DisplayDialog() method. Before calling it, you need to add: using UnityEditor; Example The code: void ExitGameConfirmation() { bool decision......
Unity – How to Run a Function after a Delay

Unity – How to Run a Function after a Delay

Updated: Sep 23, 2021
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: void Start() { Invoke("SayHello",......
Unity – Programmatically Enable/Disable a Script Component

Unity – Programmatically Enable/Disable a Script Component

Updated: Sep 23, 2021
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 was attached to......
Unity – Programmatically Count the Scenes in Build Settings

Unity – Programmatically Count the Scenes in Build Settings

Updated: Sep 22, 2021
In Unity, you can count the scenes that were added to Build Settings by using the following C# code: using UnityEngine.SceneManagement; /* ... */ int totalScenes = SceneManager.sceneCountInBuildSettings; Example The function......
Unity – Light Becomes Darker when Load/Reload Scenes

Unity – Light Becomes Darker when Load/Reload Scenes

Updated: Sep 22, 2021
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 to fix it. Below are......
Unity – How to Change the Default Gravity

Unity – How to Change the Default Gravity

Updated: Sep 21, 2021
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......
C#: 2 Ways to Check if a String contains another String

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

Updated: Sep 20, 2021
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()......
C#: Mixing Variables with String Literals

C#: Mixing Variables with String Literals

Updated: Sep 20, 2021
The three examples below show you how to use variables within string literals in C#. 1. Using the $ symbol string name = "John Doe"; int age = 99; var output = $"{name} is {age} year......
Unity: Enable/Disable Gravity from C# Script

Unity: Enable/Disable Gravity from C# Script

Updated: Sep 18, 2021
In Unity, you can programmatically enable or disable gravity for an object from your C# script as below: this.GetComponent<Rigidbody>().useGravity = true; // Enable this.GetComponent<Rigidbody>().useGravity = false; //......
Page 1 of 2 Next →