unity

Delegates and Events in Unity

  Objective: The Objective of the tutorial is to understand how to use and implement Delegates and Events in Unity. If you enjoyed my previous tutorial about Singleton, this is second of many tutorials to learn how to use unity to full potential and write efficient code in Unity. Introduction : Delegates and Events is very powerful feature of C# programming language, it helps to write efficient and clean code in unity. Delegate : A Delegate is a reference pointer to a method. It allows us to treat method as a variable and pass method as a variable for a callback. When it get called , it notifies all methods that reference the delegate. The basic idea behind them is exactly the same as a subscription magazine. Anyone can subscribe to the service and they will receive the update at the right time automatically. I know at this time everything seems very…

c#

Singleton : Implementation in Unity3d C#

Objective : Singleton is a very complex topic, In this, we try to understand basics and various implementation of Singleton in Unity3d using C#. Intro: Singleton is a basic Design Pattern. Classes implementing Singleton pattern will ensure that only one instance of the object ever exists at any one time. It is recommend using Singletons for things that do not need to be copied multiple times during a game.This is great for controller classes like GameManager or AudioController. Implementation: There are several ways of implementing Singleton in Unity, we will some of the implementation in this tutorial Simplest Implementation Above code is the simplest implementation of Singleton, but there are some issues which we have to address Singleton is not persistent across the Unity scenes. All the executable code must be attached to GameObject in the hierarchy. It is not recommended to call SingletonController.Instance in any Awake() method because, since we don’t know the…

c#

Difference Between Destroy and DestroyImmediate Unity Functions

Objective : Objective of this Tutorial is to understand diffence between Destroy and DestroyImmediate unity function Purpose of both function is same, to destoy gameobject, but there is very small difference, which is very crucial to understand, wrong use of these function can cause your app to crash So first of all little bit of theory and then some code Destroy() :  This just destroy the game object passed as parameter.  It set all the references to that game object to null at the end of frame. Syntax: Destroy(myGameObject); Let see it in code: Create new script and add this code and add it to Main Camera and click play, and just left click to create new game object and press space bar to destroy the game object and check the log in console window you will notice that first log print the status “true“, and second log print the name of currObject which…

unity

Difference Between Update and FixedUpdate

Objective : The objective of this post to understand the difference between Update and FixedUpdate unity function, and their uses. Update : Update is called once per frame, so if the game is running at 24 fps, then this will be called 24 times in a second. As we know game never run at constant frame rate because of several reason, so update will not be called on a regular timeline, means the time between update calls may be different. Uses: Update is used for moving non physics objects. Update is used for receiving Input. Update is used for simple timer. Fixed Update: As it name suggests this will be called after fixed time duration, so time duration between two consecutive calls is always same unlike of Update where this may vary.  Uses : This is commonly used for performing physics related task, like applying force on rigidbody. Now let’s see this in example Create a…

c#

Unity Interview Questions

In this, I am going to list some of the very commonly asked interview questions for unity developer profile. Unity Engine Specific Question : Difference between Update,Fixed Update and Late Update. What is Prefabs in Unity 3D? What is the use of AssetBundle in Unity? What is difference between Resources and StreamingAssets Folder. What is Batching and what is the use of Batching? Difference between Destroy and DestroyImmediate unity function Difference between Start and Awake Unity Events What is the use of deltatime? Is this possible to collide two mesh collider,if yes then How? Difference between Static and Dynamic Batching. What is the use of Occlusion Culling? How can you call C# from Javascript, and vice versa? Arrange the event functions listed below in the order in which they will be invoked when an application is closed: Update() OnGUI() Awake() OnDisable() Start() LateUpdate() OnEnable() OnApplicationQuit() OnDestroy() C# related Questions :  Difference between…