You've successfully subscribed to Hacking with Unity - Learn how to create your own games
Great! Next, complete checkout for full access to Hacking with Unity - Learn how to create your own games
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Unity Basic

Walk Through Monobehaviour
Members Public

MonobehaviourLike other fundamental parts such as GameObject, Compoent, Time, Input and Physics, Monobehaviour is an essential member for writing the script, which is the soul of an GameObject. This article is the introduction of the Monobehaviour. MonoBehaviour LifecycleMonoBehaviour is the base class of all scripts in Unity. If you use

Ben Liu
Ben Liu
Unity Basic

Get game object active status in script
Members Public

It is quite often important to know whether a game object is active or not. bool menuStatus = gameobject.activeSelf;gameObject is the game object in the hierarchy. We can use this way to determine whether a gameObject is active or not.

Ben Liu
Ben Liu
Unity Basic

Extension Methods
Members Public

Extension Methods are a feature that adding new methods to an existing class, which class is non-generic but static class. Similar to the extension concept in Swift. Features of Extension methods: Create a static class to include all the Extension methods we want to createExtension methods are staticFirst parameter is

Ben Liu
Ben Liu
Unity Basic

Output formatting in C#
Members Public

See the following examples for the formatting on float and date: using System; using System.Globalization; using System.Threading; namespace CSharpLearning { class Program { static void Main(string[] args) { double f = 0.049; // print out float: 0.049 Console.WriteLine(f); // keep 2 decimals with rounding Console.WriteLine(String.Format("{0:

Ben Liu
Ben Liu
Unity Basic

Get time difference between two date
Members Public

In C#, we can easily add or subtract two dates just like numbers. Example of getting how many days, weeks of two dates // Get time difference between two date DateTime oldDateTime = new DateTime(2020, 1, 1); DateTime newDateTime = DateTime.Now; TimeSpan ts = newDateTime - oldDateTime; // calculate how many days in

Ben Liu
Ben Liu
Unity Basic

How to create and use Dictionary in Unity using C#
Members Public

Like many other languages, C# does have the dictionary data type: Features of Dictionary in C#: Not sortedKey-value pairusing System.Collections.Generic; // example of string key and value is string Dictionary<string, string> openWith = new Dictionary<string, string>(); // example of int key and value is a

Ben Liu
Ben Liu
Unity Basic

How to convert a String to Array in C#
Members Public

Image we have a string: 123,456,78,789, we want to change it to an array, we can use the following code: string szTmp="123,456,78,789"; string[] tmp = szTmp.Split(','); for (int i = 0; i < tmp.Length; i++ ) MessageBox.Show(tmp[i]); // print out:

Ben Liu
Ben Liu
Unity Basic
Action and Func in C#

Action and Func in C#
Members Public

Actions and func are another ways to create delegates. Action is a delegate that points to a method which in turn accepts one or more arguments but returns no value. Func is a delegate that points to a method that accepts one or more arguments and returns a value. Action

Ben Liu
Ben Liu
Unity Basic