Advertisement
Swayam2004

CodeMonkey KitchenChaos Tutorial

Jul 7th, 2023
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smarty 18.80 KB | Gaming | 0 0
  1. Tutorial Link: [# Learn Unity Beginner/Intermediate 2023 (FREE COMPLETE Course - Unity Tutorial)](https://youtu.be/AmGSEH7QcDg)
  2.  
  3. ### First Day Sitting
  4. - 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)
  5. - **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)
  6. - To move the Game View Camera to the Scene Camera, press **Ctrl + Shift + F** (45:05)
  7. - 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)
  8. - Do not place the **logic** and the **visual** on the same gameobject, instead separate them. (57:07)
  9. - Make your code as **explicit** as possible, there should be no room for **misunderstanding**, like adding private to the Update function. (1:00:40)
  10. - 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)
  11. - Difference between Lerp and Slerp (1:21:25)
  12.     - Lerp interpolates in a straight line
  13.     - useful for interpolating positions
  14.     - Slerp rotates around (0,0)
  15.     - useful for interpolating directions
  16. - 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)
  17. - 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)
  18. - 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)
  19. - The 2D and 3D physics system in Unity are completely different worlds and do not interact with each other. (2:06:55)
  20. - [[What is the difference between the Overlap functions and the Cast functions like, OverlapBox vs BoxCast ]]
  21.  
  22. ### Second Day Sitting
  23. - To rotate or move in increments, press **Ctrl** before doing so. (2:19:40)
  24. - Never use **numbers directly(Magic Numbers)** inside code, create some sort of local variable. (2:22:20)
  25. - TryGetComponent() will automatically null check if a object has a certain component and return the component if available. (2:31:50)
  26. - In in-built function parameters, **"out"** means we can provide a variable for the function to return some value. (2:23:00)
  27. - [[CSharp Generics]] (2:32:40)
  28. - 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)
  29.     - Use RayCastAll to get a array of objects and check for the required interactable object.
  30.     - Use LayerMask inside the RayCast function to check objects on a certain Layer.
  31. - To learn how to interact with different object watch this [video](https://www.youtube.com/watch?v=LdoImzaY6M4) (2:37:22)
  32. - [[CSharp Events]] (2:39:40)
  33. - [[CSharp Delegates]] (2:41:20)
  34. - **? (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)
  35. - Always subscribe to events in the start method, not in the Awake method. (2:46:05)
  36.  
  37. ### Third Day Sitting
  38. - 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)
  39. - **Shift + alt + A** for enabling and disabling objects in inspector . (2:50:30)
  40. - 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)
  41. - C# is smart enough to create the underlying field for a certain property for using get; and set; (3:02:20)
  42. - We can apply accessors like public and private for both get; and set; to get the exact level of accessibility. (3:03:55)
  43. - The key point of singleton pattern is you have a single instance of something. (3:04:40)
  44. - 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)
  45. - In any extreme case, we can change the script execution order in **Project Settings -> Script Execution Order** (3:06:50)
  46.  
  47. ### Forth Day Sitting
  48. - We can use both GameObject and Transform for instantiating a game object as they both are quite interchangable. (3:12:55)
  49. - 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)
  50. - 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)
  51. - If we switch the inspector to debug mode, we can see private fields in the inspector. (3:31:45)
  52.  
  53. ### Fifth Day Sitting
  54. - Even if there is a Debug.LogError() and pause on error is enabled, the code inside the block of debug will execute.
  55. - [[CSharp Interfaces]] (3:39:15)
  56. - You can define properties but not fields in CSharp Interfaces. (3:40:30)
  57. - 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)
  58. - Different object can implement the exact same interface whilst having different implementations. (3:46:55)
  59.  
  60. ### Sixth Day Sitting
  61. - 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)
  62. - 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)
  63. - 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)
  64. - Inheritance is really powerful but at the same time really dangerous. (3:57:30)
  65. - [[CSharp Inheritance]] (3:58:25)
  66. - Whatever function defined with the accessor "protected" is going to be available in this class and any class that extends it. (4:00:40)
  67. - For every function that we want the child classes to implement in their own way, we can define it as "virtual". (4:01:05)
  68. - 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)
  69.  
  70. ### Seventh Day Sitting
  71. - 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)
  72. - 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)
  73. - Place the static at the end of the code to have a better chance of finding it. (4:35:10)
  74. - [[What is 'hiding' a function]]
  75.  
  76. ### Eighth Day Sitting
  77. - 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)
  78. - 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)
  79. - When a int is divided by another int, it returns a int. For example, 2 / 5 = 0. (4:59:55)
  80. - 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)
  81. - LateUpdate() runs after the Update() every frame. (5:07:15)
  82. - 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)
  83. - [[I heard World Space canvas is terrible for performance, is that right]]
  84. - 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)
  85. - 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)
  86.     - 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)
  87. - The generic type parameters inside <> does not only depend on name but also where they are at. (5:52:05)
  88. - [[Aren't Coroutines better for performance]]
  89.  
  90. ### Ninth Day Sitting
  91. - [[What does the CSharp 'is' keyword do]] (6:10:10)
  92. - [[What is the difference between 'as' and casting to a type]] (6:11:20)
  93. - 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)
  94. - 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)
  95. - [[What are Value Types and Reference Types in CSharp (Class vs Struct)]]
  96. - 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)
  97. - 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)
  98. - We can use **Shift + Space** to maximize a window in Unity. (6:49:50)
  99. - 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)
  100. - 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)
  101. - 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)
  102. - 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)
  103. - UV defines which portion of the texture we are going to grab. (7:00:50)
  104. - 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)
  105.  
  106. ### Tenth Day Sitting
  107. - 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)
  108. - 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)
  109. - 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)
  110. - 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)
  111. - The name of the material needs to include the font name, otherwise it will not show up in the material list. (8:15:20)
  112. - The ToString() method have parameter to set **Regular Expression** to do different things with the text. (8:20:15)
  113. - 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)
  114. - 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)
  115. - 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)
  116. - 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)
  117. - We can save the changes made to Cimemachine virtual camera in the **Play Mode** due to the option **"Save During Play"**. (8:47:40)
  118. - You can select the option **"Preserve the Aspect"** inside the image component to prevent the image from stretching. (8:48:20)
  119.  
  120. ### Eleventh Day Sitting
  121. - 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)
  122. - 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)
  123. - 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)
  124. - 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)
  125. - 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)
  126. - To hide a function with same function as the base class, we can use the keyword **"new"**. (9:05:50)
  127. - 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)
  128. - 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)
  129. - 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)
  130. - The new **InputSystem** has a great function to get the string of new Key Binding which is **"ToDisplayString()"**. (9:29:30)
  131. - 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)
  132. - Found a interesting suggestion from Visual Studio "Use [[Switch Expression]]"
  133. - To Rebind using the new InputSystem we first need to Disable the PlayerInputActions, Rebind and then Enable it again. (9:32:35)
  134. - 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)
  135. - We might need to dispose the callback parameter inside the PerformInteractiveRebinding.OnComplete() or it might throw memory leak errors. (9:35:15)
  136. - 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)
  137. - 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)
  138. - Do the Loading of JSON file into the PlayerInputActions **after you create** the object and before you **Enable** it. (9:45:00)
  139. - 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**.
  140. - 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)
  141. - 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:
  142.     - 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)
  143.     - 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)
  144. - 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)
  145.     - We can disable Automatic navigation and manually set which button will go to where using **Explicit Navigation**. (9:57:25)
  146.     - A simpler solution is to hide one of the UI canvas page which showing another one. (9:57:55)
  147.  
  148. ### Twelfth Day Sitting
  149. - 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)
  150. - 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)
  151. - 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)
  152. - 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)
  153. - We can directly **copy** and **paste** Color in the inspector using **Right click**. (10:38:10)
  154. - 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