Skip to main content

Posts

Showing posts from October, 2019

How to make a first person character controller - Unity

A first-person character controller script is the starting point of any fps shooter game. Even new Unity game developers tend to write their own fps controller script before learning anything else as it is challenging and very exciting. In this article, we gonna create two simple fps controllers from scratch and will guide you step by step on how it works. First, let's understand the basic concept of an fps controller. You should have a rotating camera that rotates in the x-axis to look up and down and the character should rotate on the y-axis to look around. There are two ways to create an fps controller in the Unity Engine.  Using Character controller component Using the RigidBody component Both have different advantages and disadvantages when using them. It depends on your game to select the best fps controller according to your needs.  Character controller based fps controller Pros: Is grounded check is built-in Has its own methods to move the chara

Singleton design pattern in unity - technoob

Singleton design pattern is one of the simplest and widely used design patterns. Singleton simply means that the class cannot be instantiated and there should be only one instance of that class. The singleton instance is created using the static keyword as we need to access it without creating a new instance.  Creating singletons is a bit different from la nguage to language. But the concept is still the same.  In Unity creating a singleton is a bit different from other languages as there are scenes and we need to make sure our instance gonna persist in between every scene. How we create a singleton in Unity is pretty easy. public class ManagerClass { public static ManagerClass instance; void Awake () { if (instance == null ) instance = this ; else if (instance != this ) Destroy(gameObject); DontDestroyOnLoad(gameObject); } } We create a variable of the class called instance. In the awake me