Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tutorial Link: [# Learn Unity Beginner/Intermediate 2023 (FREE COMPLETE Course - Unity Tutorial)](https://youtu.be/AmGSEH7QcDg)
- ### First Day Sitting
- - In the game window, **play focused** will select the game window and focus while entering play mode while **play unfocused** will not select the game window. (29:30)
- - **VSync** will set the FPS of the game view to match the refresh rate of the monitor. It is a good practice to enable this while developing a game. (29:55)
- - To move the Game View Camera to the Scene Camera, press **Ctrl + Shift + F** (45:05)
- - To make the game feel magical, in the bloom setting, set the **Threshold** to somewhere like 0.5 and the **Intensity** between 1 and 2. (48:00)
- - Do not place the **logic** and the **visual** on the same gameobject, instead separate them. (57:07)
- - Make your code as **explicit** as possible, there should be no room for **misunderstanding**, like adding private to the Update function. (1:00:40)
- - If we have multiple meshes using the same material and we change any property of the material, it will update on all the meshes. (1:18:00)
- - Difference between Lerp and Slerp (1:21:25)
- - Lerp interpolates in a straight line
- - useful for interpolating positions
- - Slerp rotates around (0,0)
- - useful for interpolating directions
- - If a animation has **"Exit Time"** ticked, this means the animation will play **completely** before transitioning to another animation and does not need any parameters. (1:33:20)
- - We should separate the script for Animation and Game Input from the logic for long term projects, as they are good code practices. (1:35:45)
- - The animations in Unity works with the exact name of the object, so if it cannot find the object, it will show **yellow text** in the animator window. (1:41:15)
- - The 2D and 3D physics system in Unity are completely different worlds and do not interact with each other. (2:06:55)
- - [[What is the difference between the Overlap functions and the Cast functions like, OverlapBox vs BoxCast ]]
- ### Second Day Sitting
- - To rotate or move in increments, press **Ctrl** before doing so. (2:19:40)
- - Never use **numbers directly(Magic Numbers)** inside code, create some sort of local variable. (2:22:20)
- - TryGetComponent() will automatically null check if a object has a certain component and return the component if available. (2:31:50)
- - In in-built function parameters, **"out"** means we can provide a variable for the function to return some value. (2:23:00)
- - [[CSharp Generics]] (2:32:40)
- - If there is a invisible wall between a interactable object and the player, the RayCast will only return the first object the ray hits. In this case, there are multiple solutions to this problem. (2:34:10)
- - Use RayCastAll to get a array of objects and check for the required interactable object.
- - Use LayerMask inside the RayCast function to check objects on a certain Layer.
- - To learn how to interact with different object watch this [video](https://www.youtube.com/watch?v=LdoImzaY6M4) (2:37:22)
- - [[CSharp Events]] (2:39:40)
- - [[CSharp Delegates]] (2:41:20)
- - **? (Null Conditional Operator)** - will check if the function is null and if it's null, then will not execute. **(Cannot pull parenthesis () after ? so use Invoke function)** (2:45:05)
- - Always subscribe to events in the start method, not in the Awake method. (2:46:05)
- ### Third Day Sitting
- - We two meshes are on the same exact position, we might see sometimes like the color flipping back and forth. To fix, simple increase the scale of selected mesh by a tiny amount. (2:49:40)
- - **Shift + alt + A** for enabling and disabling objects in inspector . (2:50:30)
- - Static means it belongs to that class and not any instance of the class. For example, if there are 100 players, there will be a single static field for all the players, but they will have different attributes like moveSpeed 100 times. (2:59:50)
- - C# is smart enough to create the underlying field for a certain property for using get; and set; (3:02:20)
- - We can apply accessors like public and private for both get; and set; to get the exact level of accessibility. (3:03:55)
- - The key point of singleton pattern is you have a single instance of something. (3:04:40)
- - If we both set the instance and subscribe to an event in the Awake method, there is random chance that the event might fire off before **initializing** and throw an exception error, which is why **we should subscribe to events in the Start method.** (3:06:00)
- - In any extreme case, we can change the script execution order in **Project Settings -> Script Execution Order** (3:06:50)
- ### Forth Day Sitting
- - We can use both GameObject and Transform for instantiating a game object as they both are quite interchangable. (3:12:55)
- - If we don't set the position of a object while instantiating, then it will spawn at an random position, so we have to set the local position to zero. (3:15:05)
- - Scriptable Objects for can be used for anything where we want to have multiple instances of an object. Like weapon, armor and in this case kitchen objects. (3:17:05)
- - If we switch the inspector to debug mode, we can see private fields in the inspector. (3:31:45)
- ### Fifth Day Sitting
- - Even if there is a Debug.LogError() and pause on error is enabled, the code inside the block of debug will execute.
- - [[CSharp Interfaces]] (3:39:15)
- - You can define properties but not fields in CSharp Interfaces. (3:40:30)
- - When it comes to base class, we can only inherit one base class. But in case of interfaces, we can implement as many interfaces as we want. (3:42:00)
- - Different object can implement the exact same interface whilst having different implementations. (3:46:55)
- ### Sixth Day Sitting
- - A feature added in recent Unity versions is Prefab Variants, where we can have a base Prefab and their variants. If we change anything in the base Prefab, the changes will occur in all the variants but we can have unique different features in different variants. (3:50:05)
- - If we add a _ (Underscore) to the name of any object, then that object will be placed at the top as the names are stored alphabetically. (3:50:25)
- - In case of kitchen counters, as their behaviors are really similar, so it is better to use inheritance instead of interface which should be used when objects have really different behaviors. (3:57:15)
- - Inheritance is really powerful but at the same time really dangerous. (3:57:30)
- - [[CSharp Inheritance]] (3:58:25)
- - Whatever function defined with the accessor "protected" is going to be available in this class and any class that extends it. (4:00:40)
- - For every function that we want the child classes to implement in their own way, we can define it as "virtual". (4:01:05)
- - For a more advanced method, we can make it abstract instead of virtual, which forced all the classes to have their own implementation like interfaces. But for it to work, we need to define the BaseCounter class as abstract class. (4:01:50)
- ### Seventh Day Sitting
- - Instead of copying and changing the properties of Container Counters, it is better to make prefab variants of ContainerCounter prefab and then make desired changes. (4:17:55)
- - In the top right side of the inspector, if we click the lock icon, then we can freely move around gameobjects into the inspector without changing it. (4:26:35)
- - Place the static at the end of the code to have a better chance of finding it. (4:35:10)
- - [[What is 'hiding' a function]]
- ### Eighth Day Sitting
- - In a canvas, Screen Space means it will occupy the screen whereas World Space means that it will exist at whatever position in world we place it in. (4:52:20)
- - When it comes to sorting order in UI images in canvas, the sorting order is based on the order in hierarchy, as the images are rendered from the top all the way to bottom. (4:55:15)
- - When a int is divided by another int, it returns a int. For example, 2 / 5 = 0. (4:59:55)
- - If we want to hide a gameobject, then hide it after listening to a event, or else in the inactive gameobject, the start will never run and it will never listen to the event. (5:02:25)
- - LateUpdate() runs after the Update() every frame. (5:07:15)
- - In some older tutorial, they might tell to not use Camera.main.transform because before it was not cached. But now that is not the problem, as it is cached in the Unity backend. So we can freely use Camera.main.transform. (5:08:10)
- - [[I heard World Space canvas is terrible for performance, is that right]]
- - There are two ways of making a simple timer, one is using a float and then the other way is making a Coroutine. (5:27:30)
- - Interfaces do not show up in the editor because Unity has no way of knowing is the interface will be implemented by some kind of GameObject. (5:50:00)
- - To solve this issue, we can create a GameObject field and expose that to the editor and get the interface in the Start function. (5:50:15)
- - The generic type parameters inside <> does not only depend on name but also where they are at. (5:52:05)
- - [[Aren't Coroutines better for performance]]
- ### Ninth Day Sitting
- - [[What does the CSharp 'is' keyword do]] (6:10:10)
- - [[What is the difference between 'as' and casting to a type]] (6:11:20)
- - If we want to store some data without any logic, then it should probable be a struct and not a class. But in this case, a class would work as well. (6:26:20)
- - If we made a custom type like a struct and we want to show it in the inspector, then we have to add the attribute **[Serializable]** (6:27:10)
- - [[What are Value Types and Reference Types in CSharp (Class vs Struct)]]
- - In the hierarchy, on the left side, there are two buttons, one of them hides the object and the other one makes them unselectable. (6:47:15)
- - Don't worry about picking a wrong option while creating Shader Graph, as it just provides a template and you can later change it. (6:49:30)
- - We can use **Shift + Space** to maximize a window in Unity. (6:49:50)
- - For a texture 2D in properties field inside Shader Graph there are two set of names, one called MainTex and another BaseMap. MainTex used to be the more common but when working with URP, they changed it to BaseMap. (6:51:25)
- - The important thing in Graph Inspector properties is the Reference which is the actual name which will be used when interacting with the Shader through code. (6:51:55)
- - The texture defined on the property is only the default and the main one is on the material, so to update the texture, only update the one on the material and not inside the Shader. (6:56:20)
- - In the previous version of Shader Graph, you could directly feed in the alpha channel with the colors but in the new version, you have to input it differently in another alpha channel. (6:58:55)
- - UV defines which portion of the texture we are going to grab. (7:00:50)
- - Unity has limit to how many sounds can be played at once. If you play too many, then some sounds won't play and which one does play is all based on **priority** inside the Audio Source component. (7:40:35)
- ### Tenth Day Sitting
- - As we have different Cutting Counters and the OnCut event is not a static event, each different counters is going to have a different list of listeners. We don't really want to have to subscribe to every single of the counters individually. So we can make a static event which will belong to the CuttingCounter class itself. (5:52:45)
- - With a static event, we can know who fired the event because of the parameter **object sender**.We can get information about the sender by casting the **object sender** parameter inside the function into that type. (7:54:00)
- - You can press 2 to convert from 3D scene view to 2D scene view and press it again to switch from 2D to 3D view. (8:13:10)
- - When you want to add effects to TextMeshPro text, always remember the effects are being applied to all the Text having the default material. So to add effects add a new material inside the TextMeshPro fonts folder, **duplicate the material, not the font**. (8:13:45)
- - The name of the material needs to include the font name, otherwise it will not show up in the material list. (8:15:20)
- - The ToString() method have parameter to set **Regular Expression** to do different things with the text. (8:20:15)
- - Instead of defining a function for the listener, we can instead create a **Lambda expression**, which is also a type of delegate, to keep the code cleaner and more compact. (8:33:10)
- - By making a class **static**, it means that it is not attached to any instance of an object. That class cannot be attached to any objects and cannot have any instanced created. (8:38:35)
- - If we don't make a class **static**, we can have both regular and static fields and properties inside it. But by making it static, we are ensuring that everything inside that class is static and that class cannot have any not-static fields or properties. This is a **clean code practice**. (8:39:00)
- - If there are variables with the same name, in a non-static class, you can use **"this"** keyword to specify the variables. But in case of static classes, you have to use the class name to access the variables. (8:42:00)
- - We can save the changes made to Cimemachine virtual camera in the **Play Mode** due to the option **"Save During Play"**. (8:47:40)
- - You can select the option **"Preserve the Aspect"** inside the image component to prevent the image from stretching. (8:48:20)
- ### Eleventh Day Sitting
- - When adding key binding for **escape** in the new Input Manager, you have to search for **escape** as pressing esc will close the window. (8:49:25)
- - Statics belong to the class and not any instance of the class, so statics fields and events will not be destroyed or reset when the scene changes. (9:01:40)
- - For the animations, you can right click on a property in the inspector (like position or rotation) and select add key. That way you don't need to move it and manually change the values back. (From comments)
- - The statics used in the singleton will be cleared automatically when the underlying Instance will be destroyed, so these do not cause any problem. But in case of static events, when the scene changes, these will not be cleared and will have the same no of listeners, so we have to manually reset the state as that will not happen on scene load. (9:02:15)
- - We can get the name and number of **listeners**(functions which are listening to that event) of any event using the GetInvokationList(). (9:02:50)
- - To hide a function with same function as the base class, we can use the keyword **"new"**. (9:05:50)
- - Unity always saved the PlayerPrefs data but sometimes due to crashes, the data can be lost. So it is better to call the PlayerPrefs.Save() for setting the data inside PlayerPrefs. (9:19:50)
- - When getting the PlayerPrefs, we have the set the default data. This is the data Unity will set when there is nothing inside the PlayerPrefs. (9:20:15)
- - When returning anything inside **switch** statement, we have to place the **default** on the top of all the cases. If we place it in the last, it shows the error "Cannot control fall out of a switch from the final case label" (9:29:00)
- - The new **InputSystem** has a great function to get the string of new Key Binding which is **"ToDisplayString()"**. (9:29:30)
- - When we use a composite binding (basically a binding which has separate bindings inside), all of those bindings are stored inside a array. The index start from the name of the composite binding. (9:30:00)
- - Found a interesting suggestion from Visual Studio "Use [[Switch Expression]]"
- - To Rebind using the new InputSystem we first need to Disable the PlayerInputActions, Rebind and then Enable it again. (9:32:35)
- - When we Rebind, it returns a object of RebindOperation, which has lot of parameters to tweak to adjust the InputSystem according to needs. (9:33:00)
- - We might need to dispose the callback parameter inside the PerformInteractiveRebinding.OnComplete() or it might throw memory leak errors. (9:35:15)
- - There is a [[CSharp Delegates]] which is called Action, which is used to define a field or parameter of a type which can hold a function. (9:37:55)
- - The new InputSystem has a function which can store the binding in JSON and retrieve them from JSON format which is super useful. (9:43:10)
- - Do the Loading of JSON file into the PlayerInputActions **after you create** the object and before you **Enable** it. (9:45:00)
- - After setting the text, the information about it is not updated right after, so we need to call the Canvas.ForceUpdateCanvases() **between setting the text and reading the values**.
- - If a Gamepad controller doesn't have a dead zone, if we lightly touch the Gamepad, then the character will move. To solve this issue is actually very easy using the new InputSystem, where we can add something called a Stick Deadzone processor inside the PlayerInputActions. (9:47:05)
- - To navigate the menu with a controller or the keyboard, one of the buttons needs to be selected. There are two ways to do this:
- - If your Scene consist of one UI canvas page, we can put desired button inside the **First Selected** field in the **Event System**. (9:59:55)
- - If your Scene consist of multiple UI canvas page, we have to manually select a button using the **Select() function** inside code when we show the page. (9:55:25)
- - If we have multiple UI canvas page open at once, it can mess up **Unity Automatic UI navigation**. We can see this navigation using **Visualize** on any button. To fix this issue there are two ways: (9:57:00)
- - We can disable Automatic navigation and manually set which button will go to where using **Explicit Navigation**. (9:57:25)
- - A simpler solution is to hide one of the UI canvas page which showing another one. (9:57:55)
- ### Twelfth Day Sitting
- - In the particle system, if we set the **Rate over time** = 0 and **Rate over distance** some value inside the **Emission**, the **Particle System** will only spawn particles when moving. (10:04:50)
- - If we set the **Simulation Space** parameter inside the **Particle System** to **World**, the particles will fall within the world and stay behind and if we set them to **Local**, the particles will move only inside the object's local position. (10:05:10)
- - A very useful component is the **Canvas Group Component** which lets us adjust the **Alpha** of the gameobject for animating. It also has other useful features such as **Interactable**, **Blocks Raycast** and **Ignore Parent Group**. (10:17:35)
- - We don't use a Canvas Group most of the time when there is only 1 image inside the canvas as we can directly change the alpha of the image. But it is very useful when we have multiple images inside a canvas and we want to animate them all. (10:26:45)
- - We can directly **copy** and **paste** Color in the inspector using **Right click**. (10:38:10)
- - If we want to place a gameobject inside another gameobject without messing up the **Transform** and **Rotation**, we can first create a gameobject inside first gameobject, take out the second gameobject and then place the first gameobject inside the second gameobject. (10:40:05)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement