C# Interface in C# explained with Unity examples Interface is another cornerstone concept in the Object-oriented Programming. They are not classes so that they can't have their own instances. Features of interface: * A class can implement more than HackingWithUnity 9 Mar 2023 · 1 min read
Unity Basic Polymorphism in Unity Like many other programming languages, Polymorphism is a feature of object-oriented programming that allows classes to have more than one type. Simply put, we can let a child class considered HackingWithUnity 3 Mar 2023 · 1 min read
C# How to auto destroy a game object after a few seconds in Unity Image we have a gameobject with a script SelfExplode attached to it. We want this specific gameobject explode with 60 seconds after spawn. Full script: using System.Collections; using System. HackingWithUnity 21 Feb 2023 · 1 min read
C# Methods in MonoBehaviour and execution order In Unity, MonoBehaviour is a class that you can use to extend the functionality of a game object. When you attach a script derived from MonoBehaviour to a game object, HackingWithUnity 20 Feb 2023 · 2 min read
Unity Basic Turn JSON string into Custom objects in Unity Store user's data or game's state in JSON, or fetch data from api call in game, Luckily, Unity does provide the JsonUtility to rescue, which can easily convert a json HackingWithUnity 16 Feb 2023 · 1 min read
C# PlayerPrefs in Unity and how to use it PlayerPrefs is a built-in class in Unity that provides an easy and native way to store and retrieve values. It can be used to save data such as user preferences, HackingWithUnity 11 Feb 2023 · 1 min read
C# 3 ways to check whether an element is in array in C# In C#, we can check if an element is in an array by using the System.Array class and its IndexOf method. Here's an example: string[] stringArray = { "text1", "text2", "text3" HackingWithUnity 10 Feb 2023 · 1 min read
C# Date time in C# It is quite common to see Date and Time used in the game, here are some frequently used methods: Get the current date time // Get the current date and time HackingWithUnity 4 Mar 2021 · 1 min read
C# Ternary Operator in C# Also called One-line if: Syntax condition ? consequent : alternative Example using UnityEngine; using System.Collections; public class TernaryOperator: MonoBehaviour { void Start() { int age = 20; string message; message = health > 20 ? "should buy HackingWithUnity 23 Feb 2021 · 1 min read
C# Namespaces in C# Namespaces are like containers for classes, which can help us organize the code, we see the same concept in other programming languages such as Java, Python and other languages. The HackingWithUnity 19 Feb 2021 · 1 min read
C# Properties in C# Like many other programming languages, C# class does have the class properties, also called fields. Example of the class property public class Player { private int experience; public int Experience { get HackingWithUnity 19 Feb 2021 · 1 min read
C# Use Singleton in Unity Singleton is a common design pattern in programming, which keeps only one copy of a variable or object throughout the entire runtime of the program. Create a Singleton is quite HackingWithUnity 18 Feb 2021 · 1 min read
Unity Basic Output formatting in C# 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 HackingWithUnity 7 Jan 2021 · 1 min read
C# How to create struct in C# Like Enumerations, struct is value type, which means if you create a struct variable which holds its actual value not the reference. If you try to modify the value and HackingWithUnity 23 Aug 2020 · 1 min read