Master Visual Scripting in Unity 3D and Create Advanced Games without Coding! | Alexander Urik | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Master Visual Scripting in Unity 3D and Create Advanced Games without Coding!

teacher avatar Alexander Urik, U Rocks!

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

39 Lessons (5h 33m)
    • 1. Course Preview

      1:59
    • 2. Unity Hub Introduction

      5:04
    • 3. Unity Short Introduction

      23:38
    • 4. Visual Scripting Introduction

      9:28
    • 5. Visual Scripting vs Coding

      15:56
    • 6. Nodes and Fuzzy Finder overview

      3:53
    • 7. Connecting the flow

      6:35
    • 8. Variables

      22:31
    • 9. Embed vs Graph Source

      12:04
    • 10. SuperUnits (Subgraphs)

      9:43
    • 11. Debugging Graphs

      3:36
    • 12. Graph Reevaluation and Cache

      3:02
    • 13. Reduce Graph Size with Control Nodes

      13:15
    • 14. Events

      6:43
    • 15. Collections and Loops

      13:33
    • 16. Script Machine vs State Machine

      12:38
    • 17. Reusable Panel UI Creation

      9:02
    • 18. Reusable Panel Script Machine

      7:32
    • 19. Reusable Panel Animation And Export

      5:34
    • 20. Bridge Builder Overview

      1:24
    • 21. Starting and Background Creation

      4:14
    • 22. Grid Shader with Shader Graph

      7:19
    • 23. Bridge Connector Creation

      7:01
    • 24. Bridge Bars Creation

      3:37
    • 25. Bridge Creation State Machine

      3:21
    • 26. Creating Bridge Bars with Connectors

      10:00
    • 27. Fixing Position, Rotation and Size

      8:39
    • 28. Multiple Bridge Bars at Once

      5:07
    • 29. Reusing Bridge Connectors

      10:33
    • 30. Fixing Bars Overlapping

      9:18
    • 31. Clamping Max Length

      4:47
    • 32. Creating Physics Joints

      10:12
    • 33. Testing Physics

      7:36
    • 34. Changing Bar Types

      10:04
    • 35. Show Bridge Load Shader

      9:45
    • 36. Creating Game Environment

      8:19
    • 37. Bridge Budget Options

      16:32
    • 38. Budget Slider Colors

      3:04
    • 39. Adding Win Loose Panel

      6:45
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

35

Students

--

Projects

About This Class

In this course, you will learn everything you need to know how to use visual scripting in Unity (previously known as Bolt) and how to create your own advanced games without writing a single line of code. This course will teach you how Master Visual scripting even if you don't have any previous experience with unity or programming in general.

The course starts with the introduction of unity for absolute beginners, so if you never used Unity before you can start learning the basics. Then we will start learning the basics of visual scripting (previously known as unity bolt). And slowly we will be discussing more intermediate and advanced stuff, and together we will touch all aspects of visual scripting (previously known as Bolt visual scripting).

During the course, you will learn the difference between writing a code and creating your graph visually. In the end, you will be able to grab C# code from the internet and use it inside your own visual scripting graph. We will finish our course by creating your own Bridge Building game from start to finish, complete with visual scripting (previously known as a bolt).

But even If you get stuck, don't worry, you can check the finished project in the resources or you can always ask me in the Discussion section.

Key Aspects of the Course:

  • Unity basics for absolute beginners
  • Learn how to make games without code
  • Learn the difference between visual scripting and coding
  • Learn how to convert C# code to visual scripting graph
  • Understand loops, collections, events, and much more...
  • Learn how to debug your graphs and fix errors
  • Understand the difference between script machine and state machine
  • Learn to minimize your graphs with the control nodes
  • Understand every variable type inside visual scripting
  • Learn almost every aspect of game development
  • Create a bridge-building game from start to finish
  • Create advanced games without coding
  • Use Visual Scripting Skills in Unity for Building Mobile (iOS and Android Games)
  • Get experience with shader creation in Unity Shader Graph
  • Get experience with Unity UI creation

Why learn from me?

I created this course to share my passion for making games and help others to simplify their work.

I am trying to find effective and fast methods to solve problems, so I hope you will find some of my techniques and tips, and tricks useful also for you.

Who this course is for:

  • Beginners who want to make advanced games without a single line of code
  • Anyone who wants to learn Visual scripting in Unity
  • Anyone interested in learning and exploring the power of Visual Scripting
  • Complete beginners who are willing to know how to use Unity Visual Scripting
  • Anyone who wants to Build Games using Unity Visual Scripting

Are there any course requirements or prerequisites?

  • Mac or PC
  • You will need to download and install¬†Unity 2021.1 or later

Meet Your Teacher

Teacher Profile Image

Alexander Urik

U Rocks!

Teacher

Hello and welcome, my name is Alex Urik and I am a visual effect artist, game developer


My skills are Unity 3D, C# Programming, Animation, and Game Design and Development.

Thank you for picking my classes!

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Course Preview: Hello and welcome. My name is Alex uric, and in this course you will learn everything you need to know how to use visual scripting in unity and how to create your own advanced games without writing a single line of code. These courses will teach you how to master a visual scripting, even if you don't have any previous experience with a unity or programming in general about me before I was game, they're a little firm. I was working as a movie visual effects are based on several feature films, including transformers or bet members of Superman. Then I release couple of games for iOS or Android. And I still like to develop some tools, surrealists, couple of assets. And I also created some old Unity courses and a video tutorials. And now back to the course. First, if you've never used Unity before and you'll start learning the basics, then we will start learning the basics of redraw scripting. And slowly we will be discussing more intermediate and advanced stuff. And basically, we will fetch all the aspects of visual scripting. Also during the course, you will learn the difference between writing and cold and creating your own graphs to visually. And in the end, they'll be able to grow up C Sharp code from internet and use it inside your own visual scripting rough. Now, our final project will be to create our own breach field of game from the start to finish completely with the visuals predicting. But even if you get stuck, don't worry, you can check the finished project in resources or you can always ask me in a Q&A section. So if you would like to create advanced games, let's start together and I will see you in a class. 2. Unity Hub Introduction: Welcome. In this video, we will talk about how to install Unity, how to work with the Unity app, and also how to start a new Unity project. So to start making games with unity, meaning to first install the Unity Hub. And we can do it directly from the Unity website, where we need to download it. After installing it and opening it, it will look similar to this. But if you are doing it for the first time, it might ask you to register to get a free license. So you need to do it first. After that, your Unity Hub will look similar to this one. Now, there are a couple of tabs on the left side of the window. But to start using Unity, we need to install it first. So selling the Install tab, and here we can see that I have already installed some different unit of antigens. Now two other new installation, click on the Add button. And here we can choose which version we would like to install. Now there is always fun recommend that release we the LTS name, which stands for a longtime support. And these should be the most stable. So far. You can see these release is from 2020, so it's a little older in my node, have all the features we would like to use for our games. And he's also our case. So we will be using the different release. And for this project we will be using version 2021, 0.1. So choose dead man to install. If you have for some reason installed a newer Unity Hub and it does not heal these version you can use also the newer one by the menus and options might be a little bit different, but you should be still fine creating these projects. Now click on the Next button here you can choose modules. They represent the platform for which you would like to develop your games. So if you are using only Windows or make, you can keep the default settings. And let's press down. Now we need to wait until your installation, we'll finish. I will cancel it because I have already installed the 2020 1.1 version. Now let's check the different tops of the hub. Click on the community tab. And here we can see links to the Unity conference call unite also there is official unit, the bloke. Also, there are only three answers where you can find useful informations or even forums where you can discuss problems and a lot of developers will help you to solve them. Now, let's click on the Learn tab where you can download lots of example projects and also can take pretty cool tutorials. Finally, let's click on a project up where you can see all your older projects. And I was using a lot of them are essentially by the window, might be empty if you are just started. Now each project have a name, then the version he was using, venue was creating it. And these version you can still change, for example, to the older one. And your project will update, but always make a backup. And because it might not work, then we have a target platform and I'm on a Windows. I have only the Windows platform module installed, so I can't change it. The viewer will install, for example, Android module. You can open your project directly for Android and it will be converted automatically. Then we can see when we are using our project for the last time. Now, if you have some old project, we just not showing inside the Unity Hub, you can use Add button and then you need to locate your project folder and select it. And it will appear here inside the project view. Now for creating a new project, we have a new button. And if you click directly on a button, it will create a project with the newest version installed. But if you want to choose vj version, you would like to use just click on a context menu and choose your desired version. So let's choose the newest 2021 and advanced version. Now, inside this window for us, we can see that we can choose which template we would like to use for our game. And the templates are basically set up some options inside our project. So we don't need to do it from the scratch. But I always use only the 2D and 3D templates because the other ones are loaded with some sampler scenes, which I would need to delete anyway. And even if I like to use the universal render pipeline, which is a grade for a lot of platforms, including the mobile. I still choose 3D or 2D template, and I will set it up myself. So now let's choose a three template. Let's define the project name and we can call it simple example. Now we need to choose the path where this project will be stored. I will peak design. And let's click on Create. And we need to wait until the project will initialize. And now we can reset the layout and the empty project is ready to start. 3. Unity Short Introduction: In this video, I will introduce you the Unity editor. And if we open the unity for the first time, the editor should look similar to this. There is a lot of bundles opens right now. For example, there is a parallel code here are he. And then we have a scene panel, again, Bucknell inspector project panel, and a console. And each panel can be moved or a tweak in size exactly how we want. But even if we changed them, we don't want. We can always reset it by clicking here on the recipe or layout. Now, let's go back to our scenario, where we can see two icons which represents camera and light. And these two objects are corresponding with our hierarchy panel. So when we open the sample scene, we can see these two objects inside the scene here. He, first one is a main camera, and second one is a directional light. Now if we want to orbit around these objects, Let's press out and we did a right mouse button. You can orbit around the viewport with the middle mouse-click, you can pan and with the mouse wheel, we can zoom. Now let's click on the camera. And we can see the indicator how wide view of the camera is. And also we can see small preview window or the camera is actually seeing any sprayer is corresponding with our game view panel and a show basically the same thing. Now when our camera is selected, the inspector panel is showing all the camera options. So for example, if you want to change background to solid color, we can do it here. And inside the preview window, we can see the changes. Now when we look closer inside the inspector panel, we can clearly see that the camera has three components. One is a transform, which is defining position, rotation, and scale of the game object. We have a component called camera, which have all Camera Options and properties. And the last component is the audio listener, which is responsible for playing sounds in our game. Now let's check the directional light, and these will have a two components. First run is also the transform. And the second one is where we can tweak all the light settings and it is called the light component. Now let's create our first game object by ourselves. So inside here are parallel. Let's praise right mouse button. And let's create 3D Object Cube. First it is asking for the name by we can keep it. So let's press Enter. And we can also see that the cube I have a four components and also the material settings. Check the game you. And we can see this q here, but it's a little bright. So to make it little darker, we can select our directional light and let change the intensity by writing the number on keyboard, hell is use a 0.5, but there is a second option. Let's move our mouse to the left side from our value input until we can see the double arrows. And now when we press the left mouse button and we drag our mouse to the left or to the right. And the value is also changing. And this is good for three king. For now, let's keep it to 0.5. Now let's go back to our hierarchy panel and let's click on the top bar and object called simple seen. These one is written in both and also it have a small Unity icon. And this type of parent object doesn't have any parameters inside the inspector has we can see it is basically showing the name of our scene. And the scene is basically a file on our hard drive, which is storing all game objects we are using inside the hierarchy panel with all their components, settings, and the actual file we can find inside the project we know inside a scenes folder, and here it is. Now for example, if you would like to rename the scene, always don't forget to save it first. Then let's rename it to exemple and these new window immediately appear. And basically Unity knows that our currency names of what's changed and it is asking if you would like to reload it. So let's press reload and we can see the scene name inside our hierarchy panel change to the example sienna. And how to see where is our scene file directly on our hard drive. Let's right-click on assets and click on show in Explorer. And we can see exec part where our project is saved. Hey, inside Assets folder, we can see also the scenes folder and there is our example see in file also be the unity metafile, which we are not seeing inside our project view. Anyway. Now let's click on our cube game object and we can see it has a three handles and they are corresponding with these icons. For example, when we click on the hand icon, the handles, these appear, but inside a scene view, we can see the hand and by dragging the mouse, we can bound the viewport. Now let's click on the arrows. And by moving the handlers, we can move our cube selected axis. Also, we can select two x's together, really square, and we can move our cube, Creeley, India's two X's also check that by moving our handlers, we are changing the values inside the transform component. So for precise tweaking, we can use also that option. Now let's undo that movement with control plus C. Now click on the rotate button and we can rotate our cube by the selected axes. Or if we click between the axes, we can rotate it in all axes advanced. And also when I press a Control and I start to rotate, I just activated the angle snapping, which is rotating cube by a steps, where one step is representing 15 degrees. Now let's press Scale button and read this one. We can scale our cube in specific axis. Also, let's select the rec tool, which is mainly used for creating UI user interface objects matter. We can use it also here for changing the size of our cube by dragging the corners or the edges. Now to change the handles, we can also use the keyboard hotkeys Q, W, E, R, and D, which will activate these buttons in the same order. Now let's select our cube and let's duplicate it. And let's move it a little bit down. And let's drag and drop it onto our first cube. And we can see our second cube star to be a child of the first cube. So now let's select our paren cube. Hamlet's start to rotate it and we can see our child is following the parent. And this is basically how we are creating a year or he is between a game object. Now, if we would like to zoom or focus on our game objects, we can double-click on it and the scene view, we'll zoom onto the object and it is working on any objects inside of here. We can also use a shortcut. So first let's sell exam object. We want to zoom and I'll go with the mouse to the scene view and let's press F, and it will do the same thing. Now, when we are checking our camera view, we can see our cubes in a 3D world, but we can switch it also to the 2D one easily by selecting that camera and switching the projection to the orthographic. And now we can see our two squares without any debt. Now when we take our camera, we can see the camera size is pretty long. So let's change the far clipping plane to 10. And we can see the size is smaller and inside our preview we can still see our cube. But for the test, let's change the far clipping plane to five and the boxes are no longer visible inside a preview. And it is because when I rotate our view, we can see the far plane is in front of our boxes, so they are not included in the camera view calculation. So let's change the far plane back to 10 and our toolboxes are visible again. Now let's delete our second cube. Here. Let's create empty game object, hell, let's call it my object. And we can see these objects have only the transform component. Inside scene view. We don't see any graphic representation. Now if we want to see something inside the scene view, we have an option to select the icon. So let's choose, for example, these one. And now we can see where these empty game object is placed inside our game world. Let's reach the game view and here are empty game object is completely invisible, and that's correct. But if we would like to see it anyway, for some reason, we still have a one option to do it. Have you can press these gizmos button. And then now all icons and gizmos are visible even in a game view. But keep in mind, these works only in the editor and it will not work in your actual game. So for now, let's turn it off. Let's go back to the scene view. And we can see we have the same gizmos button also here, which is sometime useful if we have a lot of objects and we don't want to see the gizmos. Now let's remove the icon and now you would like to create some actual mesh. So let's click on Add Component. And I'll choose mesh filter. And let's begin the capsule. But we can't see anything still hand it is because the mesh filter is only holding the information, the mesh, but it is not showing it. So to show the mesh, we need to add second component called measure ender. And now we can see something, but it looks broken because it's being held in Unity. If something is being, it usually means you have some problem with the material. And if we take a look into the Mesh Renderer material, we can see that the slot is empty. So to fix it, Let's select the assets and let's right-click. And let's press Create and let's make a new material, and let's call it the capsule material. Now let's select our game object again, and let's drag our material to the material slot and we can see the object. You have a nice white material. There is another option how to assign material to game objects. So first inside materials, assigned a nanomaterial again, then I select our material and let's drag and drop into directly onto her capsule. And it is working just the same. Now when we select our new material, we can see it has already assigned their fault standard shader with these properties. But if you would like to use differentiator, we can change it just by clicking on it. And also we can change all material properties directly on a game object. These options are basically the same. Now for example, a change the shader to unlit. And we can see the shader options different. And also our capsule doesn't have any shading on it. It is only showing the white color. So let's go back to the standard one, which was looking nicer here. Let's try to tweak some parameters and also let change the color to red. And this is basically how we are assigning materials and tweaking the shaders inside the unity. Now one of the cool things in Unity is integrated the rigid body dynamics system, which can simulate physical interactions between game objects. They could collide between each other. And it looks pretty realistic. So to test it, we need to create component called rigid body. And these one is responsible to realistically simulate the physical forces. Now to test our project, like we are playing it on some device, meaning to press this Play button and we can see our capsule is falling down to the physics is working. But we also saw that the capsule is not colliding with anything. So to fix it, we need to stop the play mode. So let's press the Play button again. Now, first let's adjust our view and VDS cube, and let's select the green is at the arrow and the view will change to the top-down. When we click on the middle of the cube, it will show the orthographic, or in other words, the 2D view of our scene. So let's unzoom it. Let's move our capsule to the middle of the world. And also we need to adjust the cube. So first, let's reset the rotation on the y-axis to 0. And they arrested the position again, 2 000, 000. Our capsule above our box. Now let's test it again and we can see our capsule is falling through the box. So let's turn off the play mode again. And what we are racing is that our capsule doesn't have any collider component on it. Let's add the capsule collider. And when we zoom in the viewport, we can see there is a new green gizmo visible, which is representing our new collider. And when we select our cube, we can see there also the similar green gizmo, which is representing with the box collider for the cube. So now it should work. So let's try it. And now we can see our capsule is falling down on the cube and it is staying on it. So the collisions are working nicely. So we can turn off the play mode again. Now, let's select our camera and light chains of projection back to perspective. So we will have nice 3D view again. Let's press Play button again. Now let's select cube l. It change the scale on x-axis to 10, and also on the z axis to 10. So we have nice ground. But watch what happened if we turn all the play mode and we can see our cube is shrink the bag to the initial size. And it is because when we are inside the play mode, the changes made on game objects are not saved. So it is very important to somehow visually indicate that we are in play mode, so we don't make this mistake again. And for this, we can open the Edit panel and click on Preferences. And here inside a color stop or change the play mode theme color to little a reddish hair. Now when we press play, we can clearly see we are in a play mode and we know we should not make any changes because they will not be saved. Now when we are sure we are not in play mode, Let's make the same change. Let's adjust the cube again. And now we can see the changes are also in a play mode and also when we turn it off. Now another important thing in the unity is to be able to know how to create user interface. So let's create a new game object. Here Let's click on the UI, and let's select the button and presenter. And we can see three objects was created, whereas van was the cameras then recreated the extra button. In the last game object is called immune systems. And all of these game objects are basically working together. Now when we double-click on a canvas, it is showing beaker rectangle of videos of representing virtual space where our UI game objects can be placed in. Right now, it is representing whole screen space of our camera, where the size of cannabis is defined by the actual pixels of the camera view. Now, I don't like to work with these huge canvases to, to make it smaller, let change the render mode to screen space camera. In here we need to drag and drop our main camera to the render camera. A variable, and now our karmas is much smaller. And I like to work with it much more. So let's double-click on camera. And we can see in the preview that we don't see this button anywhere. And then when we click on a commas and we can see that the plane distance on the cameras is 100. Well, we remember that our camera far plane is 10, so let's select our cameras and adjust the plan is dance also to 10. And finally, now we can see our button, but we can also see that our cameras is in the middle of our objects, so we can bring it even closer to the camera. So I change the distance to two. To work with the UI, you can use these 2D button. We changed the scene view to 2D one so we can easily adjust our UI game objects. Now select our button and we can see the rec tool is also pre-selected. And now we can easily change the size and also the position of our button. Now let's open the button and I changed the text name to create a capsule. And now inside again here we can also clearly see our button text. Now to add functionality to our button, we need to use some very powerful thing in a unity, which is a scripting. So first let's create a new game object and let's call it spawner script. Now let's add a new component and let's click on a new script and let's write spawner script. Here we can see the new component with the same name appear on our game object. And also inside the assets folder, we can see there is a new file which is called spawner script as well. Now let's double-click on our new component and the application called Visual Studio should appear. Because for the scripting unity choose the programming language called C Sharp. We can use it inside the Microsoft Visual Studio. We just professional environment for programmers. Now when our strip is opened, we can see it have two methods. One is a start and a second is update, but we will not use any of them, so we can delete them. And we would like to create different methods which will be spawning new capsules to the scene when we click on the button. So the spout new capsules, we first need to access it somehow also inside the script. And for these we can use a variable. So let's create a public variable would be the type of game object, and let's call it my capsule. And now let's create a new public void method called create capsule and insight. Let's use a method which is called instantiate, which can create new game objects while we are playing our game. Now the instantiated method, hell, a lot of versions or in other words, lot of overloads. But we will use this one. So first it needs our capsule, then it needs the position where we want to create it. So let's write new vector 3. Payloads use the position of x-axis to 0, a y-axis position to be five, and a z position will be the 0 again. And the last parameter is a rotation, and we don't want any. So let's write quaternion that identity. Let's save it, and let's close the Visual Studio. Now we can see our public variable appeared inside the component, so we need to fill it. Now. We need to remember, if we want to instantiate some game object, we need always to use a prefabs. And what is a prefab? Prefab is basically a container which includes our game objects together with their components. And basically the prefab is stored in a separate file. So to do it, Let's create a new folder and let's call it prefabs. And let's open it and let's select our capsule, how it's drag and drop it into the prefab folder. And we can see the new Brief up is created. And we know it because a prefab has a blue box icon. Now when we select it, we can see it has all our capsule settings included. And to modify this prefab, we can also open it. And now you can see only the prefab object itself in isolation from arcsine. And to go back, and let's click on this big arrow. Now let's finally use it with our spawner. So let's drag and drop it into my capsule variable. And also let's delete the old capsule from the scene. Now to connect our smaller with the button, we need to select our button. And here we need to press the Plus symbol. And we can see new entry inside onclick event appeared. And we can feel it first with our spawner object, and now we can choose the function we just made inside a Visual Studio, and it is inside a spawner script and it's big the creative epsilon. Now let's write heavy can see when we click the button and your capsule will appear until they fall down. Unity, there is another option how to create these type of functionality. And you can do it without writing a single line of code. So for this first delete the spawner script, the game object with the pressing Delete button on your keyboard, then inside the button, Let's remote onclick event. And now let's create another empty game object and let's call it spawner graph. And let's add a new component, and it will be from the visual scripting group in here, let's choose the script machine. They changed the source to embed. So we will not save the graph, but it will be sitting directly on our spawner GameObject. Now let's click on edit graph. We need to wait first time until the visual scripting we'll initialize and how these new window appear. So let's look in here and let's resize it a little bit. And now we can see we have the same two events, start and update, which we also had inside our C-sharp script. But again, we don't need them, so let's delete them. Now to use the button onclick event. Inside this graph, we can right-click on a workspace area, and let's click on the Events group. And here let's click inside the UI. Here Let's choose On button click event. We need to connect it with the actual button. So let's drag and drop our button on it. Now let's create another node called instantiate, and we can choose the same one who was using inside our C-sharp script. And it is the one with the position and rotation. Now let's connect them together by dragging this green arrow output to the other green arrow input. This connection is called flow. Now our instantiate an ODE needs to feel some parameters. So first let's drag and drop our prefab into the origin of slot. Now for the position, change the Y axis value to five. So the position will be the same as in our script. And for rotation, Let's create a new node. And let's find it by writing quaternion dot identity. And let's pick it. Now let's connect it. Now let's try it. And we can see that readout single line of code. We created the same behavior as we did in a C-sharp. So we can see a visual scripting and unity is also very powerful. And it's basically everything what I wanted to show you in this video. So I hope you liked it. So thank you and see you in the next video. 4. Visual Scripting Introduction: In this video, I will show you how to start with visual scripting in Unity. First, we need to create some game object. So let's create, for example, 3D cube. Now to work with visual scripting, we need to add on our pure spatial component. So let's click on visual scripting group. And here we can see components with the name screed machine and state machine in Agile show you the differences between them in other videos. But for now, let's choose a screed machine. And now we can see we have a new component attached to our cube and either have some options. First options is a source where we can define if the source will be a graph. That means if we will save it to the separate file or we can choose embed in our original graph will be saved directly on a cube game object. I will also explain these differences in more details in the following videos. But for now let's choose m bit. Now let's press on edit graph. And if we are doing it for the first time in the project, we need to wait until the visual scripting we'll initialize. Now these new window will show up. Let's look into the right side and let's expand it little bit now inside this window and there is everything we need to work with visual scripting. Now let's learn how to maximize this window. So to maximize it, we can double-click on a workspace. And if we double-click again, we are back to the smaller window. Now, there is a two more options how to maximize it. First one is a press Space and shift together. And this shortcut works on every unit in Windows. And to go back, Let's again press Shift and space together. And the last option is to click on this full screen button. Now inside our workspace, we can see there are two nodes. And to see more information about them, Let's click on them. And here inside our graph inspector, we can see some more options and sometimes also a useful informations. But right now you can see that the node have only the output, and this output is called the flow. And later we will learn data. These two nodes are called events, and we can connect them with the other nodes, which can change behavior of our game object. So let's create our first note. Let's right-click on the work area. And we can see nice searching window. But for now, let's just search for rotate around node and click on the selected one or press Enter. And if our node is selected, we can read some information in a grub inspector. And these nodes basically rotate our game object around some point in space. And also we can choose the axis of rotation and also rotation angle. Now let's maximize the window. And we can see our node have van flow input, which is basically triggering these node if it's connected. And then we have four more inputs per Zhuan is a target with the type of transform. And this is defining reach Game Object Transform component. We can rotate and we can see in our case is filled with a DC value. And it means that we will be rotating the transform on the same game object on which this visual script is attached to, and in our case is our cube. So basically we will be rotating our cube itself. Now second parameter is a point of a vector p type. And this one is defining the point around which we will be rotating our cube. And currently is setup to 000, 000, which is the same position is r cube. So right now, the queue will be rotating around its own center. Now there is an axis input of a vector tree type, which we'll define the axis of rotation. And Ryan out there is a 000 000. So now to choose some angle, we need to change it to some different numbers. Now we have a last parameter and it's called angle. And it is a flow type and it is defining by how much we would like to rotate our cube. And also later we will change this number because right now is set to 0. Also we can see output, which is again a flow, but it is useful only. You would like to connect different nodes after our rotation. Now under our graph inspector, we can see also one more window we just called Blackboard, where we can create new variables. But I will explain it more in later videos. So now let's minimize our window. Now we would like to connect our start event with our rotate around note. And for this, let's click on the green arrow output. And let's drag the line to the Rotate. Note again a green arrow input, and now release the mouse and the connection is ready. Now to test it first, we need to change the angles to, for example, 15 degrees. And also you would like to rotate it in a y-axis. So let's change the second axis to one. Now press Play button and we can see when our game started, the start event triggered the rotate around node. And our cube is slightly rotated. If we check the cube transform component, we can see the rotation in y axis is also 15 degrees, exactly how we want it. Now let's turn off the play mode now to a remote connection between our nodes. Let's hover the mouse over the flow input and let's press right-click and we can see the connection was deleted. Now let's go into the flow with the update event and let's press Play. And we can see our cube is rotating around over and over. And it is because the update event is triggering our rotate node once per frame. And if our game is running at 60 frames per second, we can say 60 FPS and the Update Node is triggering the rotate node basically 60 times per second. Now, I was talking that our rotate around note how these four inputs, but we can see in front of them they have a small circles, and that means we can connect them with the other nodes of the same type. So let's try to connect something to the angle input. Now to find the type which angle input is expecting, let's click on our rotate around node and we can see the angle needs the floating-point number or a float type input. So let's right-click inside the workspace, and let's write floridly Terrell. Let's connect them together. And now let's change the node externally to, for example, 25. And let's test it. And we can see our cube is rotating much faster. Now, if we look closely to the fraud literal connection, we can see the values under the blue connection. And this is very important to double-check if our graph is doing what we want. And we can turn on or off this functionality by bracing on these values button. Now let's maximize the graph and let's disconnect the flow. And now we can still see our nodes are fully visible. But if you would like to see which nodes are not connected to anything which can run them. We can click on the dean button. And a now all these connected nodes will be slightly transparent and we will know they are not working right now and now when we connect them back, they are fully visible again. Now let's praise the carry button and let's try to move some nodes. And if we move the rotate node, we can see nothing happens. But if we move the flow note, it is carrying the connected rotate note and they are moving together. Now Let's connect the flow from the start event. Let's move it again and we can see only the first connected node is moving. I personally don't use the scary option that much. Now let's select these three nodes. And if you would like to align them, we can click on Align button and let's use our middles. And we can see the nodes are aligned vertically and to distribute them horizontally, we can click on distribute. And let's click distributed centers in the now they have exactly same gaps between. Now sometimes it can happen. We are somewhere else in our graph and we don't know if the graph have some notes. So we can always click on the Overview button and it will zoom in center of our workspace where we can see our notes. Last thing I would like to show you is when we have some small functionality ready in our graph. And we would like to separate it from the other nodes. We can group our nodes by pressing control. And let's drag the rectangle around to include our notes. And we can see there are grouped. Also. We can change the group name and let's call it rotate around. And here we can also change the group color. And let's use the red van. And, and now we have a nice group separation inside our graph. And that's basically everything for this lesson. So thank you and I'll see you in the next one. 5. Visual Scripting vs Coding: Welcome. In this video, we will talk about programming using visual scripting and how can see sharp help us a lot to create animations games. Now we know that C sharp is a professional programming language and we can use it inside Unity. But we also need to know that a lot of code made by C-sharp can be easily recreated by unit is visual scripting. So at the end you will see these completely different ways how to program. Our games are pretty similar. Now I will show you our sample seen. Here we have a simple cube game object. We'd already attached script machine component and v, the NBA draft. We have these empty game object and we call it target. And on this one, I turned on the blue icon so we can see it better. Now imaging, you want to create some game and your first task will be to move our cube exactly on a target position over some time. And basically, if we are using visual scripting for the first time, we really don't know how to do it. So to tackle this problem, well, electric Internet and we know this is unity related questions. So let's start with a unity and then let's write our problem. So let's write how to move game object TO art's position and let's search it. Now let's check this link which is from Unity answers. And we can see, we can choose from these two replies. And I will check the second 1 first because it has less code and also more likes. So let's grab this code and let's go back to Unity. Now let's try to recreate the C Sharp code inside our screen machine. And we can see the C-Sharp code is using the update method. So we can use the same update event inside our visual scripting. And let's delete the star V1. Now also, let's maximize the window. Now we can see inside C Sharp code, we are doing some calculation to transform that position and to do the same in our graph, Let's create a new node and let's write the same thing, transform dot position. And we can see in our code they are setting these values. So let's pick the set position note, and let's connect it to be the update event. Now you can see they're calculating position with the move towards method. So let's try the same. Let's try to find vector 3 dot moved of art. And there it is. So let's use it. Let's connect its output with a set position input. Now for the first parameter, they are using transform that position. So let's write transform that position again. And now we don't want to set it, we want to get value from it. So let's use the get position node and let's connect it to the current slot. For the second parameter, they are using target that position. And when we look inside our scene, we also want to move towards the game object we called target. And because we are using embedded graph, we can easily bring our target game object there just by dragging and dropping it into our work area. And now this window will appear and we want to bring the game object itself. So let's click on the first option. Now we need to get position from it so we can reuse our good position node. So let's duplicate it with control plus D shortcut. And let's connect them together and also let's connect them with the target input. Now for the match these towns, they are using a state variable. But when we look closer, we can see that the step is basically multiplication of a speed and Time.deltaTime. And also we can see the speed is another variable which is a public one. That means they can change it inside the inspector. So to create similar thing lates first to recreate the step calculation. First, let's create multiply node and let's print Enter. Now for the speed, we can create also a variable and if we want to be visible as well inside the editor, let's click on the object variable and laser light speed. Click on the plus symbol, and let's define the same float type. Now let's bring it to the workspace. So let's drag it there and connect it with the multiplied out. Now for the delta time, we need to add a new note, Alice, right? Time.deltatime. And let's click on the first option. And also it's connected. And also let's connect the Multiply node with the max distance input. Now let's minimize our window and we can try it. But before we press Play, Let's elect our cube. And we can see the speed variable is really visible in our editor. But right now it is set to 0. So if we tested, you can see nothing happened. So let's change it to run in our queue is really moving towards our target. And to speed it up, Let's change the value. So this is how we can reuse a C-Sharp code inside the visual scripting. Now other thing we need to keep in mind when we are working with visual scripting. When we opened the fuzzy finder, it have a lot of nodes, but sometimes we can't find the right one, which for example, Xist in a C-sharp, but we don't have it there. So let's create one example. Let's create new UI text mesh bro text. And also let's click on Import essentials. Now let's go to 2D view. And double-click on canvas and let's align the text a little bit to the corner. Now to change this text inside a visual scripting, we need to use text Mesh, bro, you said texts and old, and his name is also written in the source. So to find it there, Let's write uy. And we can see there isn't any node with this name. But luckily, there are some ways how to add the new nodes inside our visual scripting. So first we need to go to Edit panel here to the project settings. And let's open visual scripting. First, we can open the types. Let's scroll down and let's press Plus symbol, and let's try to find it there. Let's write days much pro, and we see also, and I think so let's delete the entry. But we have also second option. So let's open the node library and let's scroll down and again, praise the blessing mole. And let's try to find it here. And we can see it is there, and we need only the first one. So let's click on that one. And now we need to remember always when we are adding new types or assemblies to the visual scripting, we need to click on the re-generate units. So let's do it because these nodes needs to be initialized for the visual scripting. Now let's close the window and let's go back to our graph. Let's try to write uy, and now you can finally see a lot of nodes. So let's continue with a set text. And we can see there is also a lot of them, but each of them have different parameters. And in C-Sharp, when the same function have a more versions by the same name, we are calling it, have more overloads, end for now and choose the last round without any parameter. And also we need to connect it with our text. So let's drag and drop it to the target slot. Now if we want to display some text, we can directly write here what we want or we can create new node called string literal. Alice, right, whoo. Now let's maximize the window and we need to connect it to some event. So let's add a new start event and it's calling them together. Now let's try it. And we can see this working. Now let's select our cube and let's imagine you would like to have options to modify lot of properties. And runaway will be to create a lot of variables one by one in the visual scripting, which can be really time-consuming, we can use the second option. We can create these variables in a C-sharp script and then use them inside our redraw scripting. So let's add new component. Let's go to the new scripts option. And we would like to create a brand new C-sharp script. And let's call it box values. And it's created. Now we can see our script file appeared inside our assets. And also we have the component with the same name inside our cube. Now let's wait some time until visual scripting we'll refresh. And now let's open our script by double-clicking inside the script component. And we can see the visual Studio will open and inside is our script. And we can see the script to have a same functions. Start an update, which we always have when we create new visual scripting rough. And if we move our window we are using then also right now. But there are differences inside a C Sharp language. Here. They are called functions or methods muddy in visual scripting, they are called events. Now let's go back to our task. First, let's delete these two methods. And let's define some variables which we would like to change on our cube and to see them inside inspector, they must start always be the public keyword. And then we need to define a type of the variable. In first we want to change the speed, so we need a float type, hence the name will be my speed. Now the second variable we would like to change our size. So let's write public and then type will be vector or three, hence the name will be my size. And for the last one, we would like to change our rotations. So let's write public, and we want to define angles on each axis. So we can use vector 3 as well in the name will be my rotation. Now let's save the script Control plus S. And now we can close the Visual Studio. And now we can see our variables appeared inside our script component. So let's change my speed to five, my size 2, 1, 3, and 7, and my rotation to 45 degrees in all axes. Now to use these variables inside our visual scripting. So first we would like to replace our old speeds variable with our new one from C Sharp script. First, let's try to find them in a fuzzy finder. And we can see we don't have them there. So let's repeat the process how to add the new types and assemblies into the visual scripting. So let's go to the Edit panel. Let's open the type options and let's add the new type. And let's write bugs values and we can see it, it's there. So let's use it. And now let's regenerate and holds. Now let's rank to find books values again, let's open it and we can see here our variables which we can get or set. And also there are other nodes, but we will not using them. So let's pick the first one, get my speed. Let's reconnect it. Alice delete the old variable. Now let's turn off the 2D mode and I'll zoom back to our cube. Let's test it and we can see our C-sharp variables are working just fine. And when we click on a values button, we can see that the value is five, exactly how we are setting it. Now to use my size variable, Let's add a new node called Set scale, and let's pick the transform said local scale. Now connected with the flow and my size variable, we wanna getting node. So let's connect them. Now we can test it and it is working fine. We can also see the values are same. And here van 37 and also transform node Hello again the same values 137. Now to use the last variable, Let's use set rotation node. And let's connect it with the flow. Now let's bring our rotation variable again and getting one. But when we try to connect it, we can't make the connection. And how to check why. Let's click on the set rotation node. And we can see inside the input, it is expecting the quaternion type. And when we check our variable output and we can see the type is basically vector three. They're not compatible, but we still want to connect them. Now you may be thinking there must be a way how to do it. So let's again check the internet and let's write unity. How to convert vector 3, two quaternion. Heloise Jake, the first link. And we can see in C Sharp there is a possibility to use quaternion dot Euler method. And also when we check the second link, which is the Unity documentation, we can see inside Unity, this method also exists, so let's try to add it inside our visual scripting. Let's find quaternion dot oil layer, and let's pick the first one. But now again, we can't connect them. So why is that? So let's try again and drag our connection little bit. And let's really SSID. And we can see the fuzzy finder opened body. There are different options. And because we are dragging it from a vector three type, we can see all possible vector three nodes. So let's try the expose one and the exposed node will show all the possible outputs on the vector TreeNode. And inside the visual scripting, there is a lot of nodes which have these eggs pose note, so you can check it later by yourself. Now you can see this note is really big, but at least we can see it have our XYZ outputs, which we need, so we can use them. Now let's connect the Euler note also with the set rotation. And we can test it. And we can see this working fine. But our graph looks really bad and I don't like it. I would like to see only node which we are using. So let's delete these big node and there must be another way how to get these three values. So let's create a new node, and let's write good X and these nodes exist. So let's pick the vector P1. We can also get y and also gets it. Now, this will work for sure, but there must be an even better way. So let's go back to internet. And we can see in the quaternion oil layer hail two versions, or in other words, to overload. And the second one is expecting the vector 3 NADH. And that's basically what we want. So let's find it again in our visual script. Let's ride again quaternion dot oil layer. And we can see there is the second one. So let's use it. And we can see this one is expecting the vector pre, so we can connect it directly with our variable. So let's delete that all nodes. We don't need them anymore. And let's reconnect the new ones. Let's try it. And we can see the rotation is working how we want. And that's basically everything for this lesson. And I hope now you will be able to create your visual scripting graphs also be the C-Sharp code. So thank you and I will see you in the next lesson. 6. Nodes and Fuzzy Finder overview: Hello. In this video, we will be talking about visual scripting nodes. Right now. We already know when we would like to create new nodes. We just press right-click inside our work area and a new window will appear with is called fuzzy finder. And in this panel we can see a lot of groups. So let's check them briefly. First group usually shows all the node related to the game object on which the screed machine is attached. In our case, it is a cube game object. And when we open the group and we can see each hour cube components as a separate groups, where each group have an old notes are related to this component. So let's go back. And then we have a code base where we can find nodes separated by C-sharp language namespaces. For example, we have text Mesh bro, namespace, where we can see all the tags match burnout. Then we have unity and unity and jam namespace. And at the end we can see holder in m literals we can use in our graph. Now let's go back and we can see we have a lot of other groups like collections, control, events, logic, mouth, and so on. So we can explore a lot of very interesting notes. Now let's talk about the node, which name is this? And when we check closely in our graph, we can see we are using it already in the three of our nodes, and maybe we not even noticed it. Now let's bring this from our fuzzy finder has a separate note. Let's plug it to the source input and also let's connect it, be the second node. When we tested that behavior is the same. Now if you are asking what is this node basically doing? It is referring to the same game object on which is this screed machine attached to. So in our case it is referring to the cube. Now to show you that I am right, let's create another 3D object, and this time let's choose a sphere. Let's move a little higher. Now let's bring our sphere to the graph. So let's drag and drop it there. And it will create new game object node, which is referencing our sphere. Now let's delete our these node. And let's connect it with our two nodes. And now when we test it, we can see all calculations are made on a sphere. Now let's bring to our workspace new node called Subtract. And if you are starting with a visual scripting, it might be confusing. What we can read inside the node because the first line is showing a, a minus B in the second line is showing b. So what does it mean? And basically we are reading it incorrectly. A and B are referring to the inputs of the subtract node. And the output will show what these node is calculating and it is doing a minus B calculation and the outputs represent the result. And also inside fuzzy Finder, we can a lot of times C informations about the nodes, what they are basically doing. Not every node has it. But for example, if we check this time group and we can see there are a lot of useful information is retained. And when we bring one note in our workspace, we can also read these desk scription in a graph inspector. And is everything. This was basically a short introduction to the notes, to the fuzzy firing there and how to work with them. So I hope you liked this lesson. Thank you. And ASU in an XOR. 7. Connecting the flow: Welcome. In this video, we will talk a little bit about the flow connections. So let's start. Let's open our already well-known graph. Hell, it's Dong about how and why the flow is connected in this way. So first let's disconnect our flow. So let's go to the end of the flow and let's brace right mouse button and the flow will be disconnected. Now to connect any flow, I think we already know we are grabbing this arrow output. We are connecting it with the other arrow input. And we are basically doing the flow connection always from the left to the right. Now when we check how the set position is calculated, and if we have connected some inputs like we have now, first the set position needs to receive the values from them. So in our case, it needs a new position calculated inside a move towards and out, but move towards node can't calculate the new position right away because it needs the values from their own inputs. So let's go to the first input. Luckily, this is a good position node, which can send the value right away to the move towards node, then the second input can be calculated right away because these Van have its own input. So it needs to wait until these target input give him the game object, and only after that it can send the values to the move towards node. Now the last input needs to get result from their own inputs and only after date, it will multiply them and send the result back to the towards node. And now finally, how towards node to have all the values from the input. It can calculate new position and it will send it back to our set position out, which will set the new game object position. And we are done for this frame. And because we are using update event, all these calculations are happening every frame. Now let's discuss another thing. A lot of nodes have also the flow inputs and outputs. So there must be a lot of ways how to connect the flow. So let's reconnect our flow with this move towards node because we can use its flow inputs and outputs. And when we tested inside a play mode, it is doing the exactly same thing as before. So the question is how we can decide to connect or not connect with the flow to get the same results. And we are lucky. There is one button which we didn't discuss before, and it is called the relations button. And when we press it, we can see aligns inside our nodes, which represent how each node is calculating their results. And there is a role I am also following. And it is basically if the flow line input is not crossing the data output like V0 inside a move towards node, but we don't have it in a safe position out. So that means there is only one straight line going from flow input to float output. We basically don't need to connect this node with our main flow. And if this node is not the last one we want to connect. I will show you the opposite example. Hell, it's other new node called rotate around. And when we connect it after our set position node, and also with this output enolate spin it in a y-axis. And for the angle, let's use a 15 degrees. When we tested. It is working good. But now let's disconnect all the flow connections. And let's reconnect it only with the last node. Now we already see some indications that something might be wrong because the note is orange and it is showing us some warning this way. And when we test it, first we can see some error in the console. And also our rotate around node is fully red and our cube is doing basically nothing. Now when we check the relations, we can clearly see the set position. Note does not have only the straight line going from the flow inputs towards the flow output. It has also the second line which is crossing the data output. That basically means if these nodes wants to calculate the result, it needs to be connected with our main flow. Now let's reconnect the node properly. Hell, it's right. And we can see this time is working again. Now let's discuss another thing. And this one is the execution order. And you need to keep in mind this is very important to decide which node you want to connect after other. Because for example, if we disconnect the flow and our position node, we'll reconnect it somewhere else. We are still using the same nodes basically, But if we tested, the cube is doing completely something else. So always keep in mind that your connection also need to make sense. Because if you look closely, the set position is getting the result from a good position. So basically it is not changing it by the rotate around is rotating the cube. After we move it, we did the move towards node. So the rotation axis is slightly offsetted every frame from the center of the cube. That's why the cube is also moving. And basically the whole logic is very weird right now. So let's reconnect it back. And now we are basically setting the new position, which is moving to our target, and then we are rotating around our cube. So this makes sense now. And this is also the order how we are reading our graph. We are reading it from the left to the right. So that's basically it for this lesson. I hope you learn something. So thank you and I'll see you in the next one. 8. Variables: Welcome. In this lesson, we will talk about visual scripting variables. First, let me show you our scene. Here we have a graph which is moving the cube towards the target capsule until it reach the same position. These graph is attached to the cube. And we are basically setting the cube position, which every frame is getting new position from this move towards note the move towards nobody's getting current position from the cube, then the target position from our output, it is moving how our cube, little by little, each frame by this flow number, which is currently one, multiplied by a time between the last frame and current frame, which is called the delta time. Now sometimes it would be a nice to have an option to change some of the values even if we close the graph, for example, it would be cool to change speed of our books. He luckily, when we create any scribble machine, we can see there is also a second component called variables. And read this component, we can make a new variables which can be used inside our graph. We can modify them directly here inside the inspector. So let's create our first variable and let's call it speed, how it spreads the plus symbol. Now we need to define the type of this variable head. It will be a floating point number. So let's big the float and let's define the value, for example, to be five. Now let's open our graph. Let's maximize it. He now let's just click on the object variables stub and we can see it here. And basically now we know that every variable defined from the variable components are called object variables. And it makes sense because the component sitting on that game object, so it belongs to the object. Now to use it instead of our flawed liter, how plates grab it and let's drop it inside our workspace. Let's reconnect it and let's delete the old flog note. Now, if we tested, we can see the cube is moving way faster. But always we can adjust the speed to be faster or slower directly from this inspector window. Now, if we go back to our graph, we can see we have a lot more variable types and they are basically defining the scope of their accessibility. First, we have an option to make a graph variables which work only inside the Open Graph window. Then we have object variables. We already know which can be accessed from the game object itself. Then we have seen variables which can be accessed from any game object. We just part of the scene. Then we have up variables which we can access from any scene, reduce part of our project. And then we have the last one, the saved variables, which can be saved to the hard drive or other storage. And we can get back the saved value every time we close and then reopen our game. Also, there is one more variable type we don't have in these group, and it is called flow variable. So to test it, Let's change our graph and let's calculate a distance. So we need to add a new vector, three distance node. And we would like to calculate distance between our cube position and between the target capsule position. And because the result of the distance you would like to reuse in other parts of our graph. Let's save it as a new variable. So later we can get it back. And if we know, we will be reusing these variable inside the same flow, we can use this flow variable type. So let's test it. Let's create a set flow variable. Let's define the name to be distance, underscore flow var, headlights coming the value we want to save. And let's connect the flow from the set position node. Now for a better organization of this flow, we can create new node called sequence, which can split our flow connection into multiple. And we will clearly see what each flow branch is doing. Now let's bring it higher. Hell is reconnected with our update. Event. Handlers connect the first output with the 0 index to the set position. Note, now somewhere down, Let's create another node. Rotate around. Let's reconnect the flow from the second sequence output and to get the value from our flow variable, Let's first do it in a different way. Let's create new node. Let's go to the variables group. In here, click on the floor group, and here let's go down and we can see we have an option to get our variable already with pre-filled the name. So let's peek. Get these towns flow var note, and we can see this node has already filled with the name. So let's plug it to our angular input. And we basically want if the D Stan will be shorter, our cube and a capstone rotation, the slower as well. Now to rotate the capsule around its axis, Let's duplicate these two notes. First, conic upsell to the transform input and then connect to the good position to the point input. So now the capsule will rotate around their center. And let's rotate it in x angle. So let's write one here. Now we can try it, but first let's change the speed to do and let's press Play. And basically the capsule is rotating and a vein, that distance is shorter. The rotation speed is also slowing down until it stopped completely. So these working. Now, if for some reason people would like to use our flow variable in a different flow. So let's create new event called late update, which is basically doing the same thing as our update event only in every frame, the late update is calculated after the update event. Now let's delete the old flow analyzer, reconnect the late update. Now let's press Play. And we can see the first part of the graph. He's working. So the cube is still reaching the target, but the rotate around is not working at all. And we can see our good flow variable node is red, so there is an error evaluating this node. And when we click on it, we can read that the variable is not found. So now we know for sure here we want to use the flow variables. We can always use them only inside van connected flow chain. Now, if for some reason we can't use one flow, but we still want to use variables. And if these different flows are created in the same graph, we can change the variable scope to the graph and then the setup should work. So first let's click on our set flow variable node. Click on this drop-down menu. Let's big the graph option. Let's rename our variable to distance graph var, so we know for sure it is a different name. Let's select the name and let's copy it. Now let's go to the set variable. Note first, change the scope to the graph. Again. Analysts based our name here. Now we basically did not say it our new variable inside the Blackboard, but let's still taste our scene. And we can see the variable appeared there anyway. And it is because here we are first setting the variable inside our flow. These variable, it'll be created automatically in this Blackboard. Now to be honest, I don't recommend it to do it this way because you are basically losing track of your variables and you can use a lot of them inside your graph. It could starting to be a messy because you don't know which variables are created on the fly and very are using them. But it's still good to know that this option exists. So let's create this variable manually. So let's grab the name and let's paste it in a new graph variable slot enolates, press Create. And now I will show you one other thing. I will basically not specify the type. And again, because we are setting our variable first and only then we are getting it somewhere else. These type of the variable will be set at automatically. So let's try it. And we can see the type was assigned, and also we can see the value and everything works as before. Now let's imagine that for some reason we want to use a variable from this graph inside a different visual scripting graph. So instead of calculating capstone rotation here, let's calculate it inside a new graph, which will be attached to the capsule itself. So first let's select these nodes and let's cut selection. Now let's select our target capsule plates, creating your screen machine. And let's reach graph to ambit. Let's open it. Hamlet's delete our default events and let's paste how gutted selection from the cube graph. Now we can delete the capsule game object. And now we can see the nodes are using this, so they are referencing our capsule anyway, but the graph is little bit cleaner. Now, if we would like to test it right now, we will see the error because the variable does not exist in this graph. So let's try to bring the Cube game object. Inside the graph. But we still don't have an options to plug it to this. There are variable, so this way it will not work anyway. And it is because as we know already, the graph variables only works inside the same graphs. So to solve it, Let's go back to our cube graph. Let's delete our graph variable, change the set variable note to the object type, and I change name to OBJ var. And also let's copy the name. Now let's click on an object variable and we can see we are already using van, but we need also to create these one. So let's base the name here and let's create it. And I change the type to float. Now we can go back to our target capsule and let's open our graph, handle it, change the type of this variable to object one. And finally, we can see there is a target game object slot where we can plug our game object. Well, let's do it. And also let change the name of the variable to be RBG var. And now we can test it. And we can see it is working as before. And now we know how to use different game object variables inside different graphs. So this is very handy. Now to show you the next variable type, it changed the name of our capsule to Monster, an r cubed to be a player. And we would like to make a setup if our cube will move to the most position, the most trivial ate it. And there is a lot of ways how to do it. But I choose the one where we can use scene variable will be basically accessible from any game object. So let's create one. So inside our player graph, Let's click on the scene of variables button, and let's create a new one called D-dimer lost. Hell, it change the type to Boolean so it can be true or false, and we can see the initial value is false. Now when we check the monster graph seen variables, we can see it also here. And also maybe you didn't realize when we are using visual scripting, there is always on game object created automatically, and its name is also seen variables. So we have also these option to set them from the inspector directly and we don't need to go to other graphs. Now let's go back to the player script. Use it. Let's first check if these stance is equal to 0. So let's create equal note. And also let's create float literal. Hell, it's connect the distance and the flow to be the equal note hand to check if the distance is 0, Let's create the IV note. Let's connect it also with the flow here. Now if it's true, It's grab our Did I lost variable. And while we are dragging it, let's press out so we can set it. And now let's connect it to be the true branch. And let's create a Boolean literal and set the value to be true. And also to visually see that our monster capsule will either the player, we can create a set local scale. Note how it's connected to our flow and the default values are 0. So basically the player scale will shrink to 0 and it looks like it will disappear. Now let's go back to our monster capsule and we want, after our monster will eat the player to get bigger. So first let's create evil node and connect it with our flow and also connected with our DTI lost seen variable. Now to make it bigger, let's create a set local scale node. Hello, I change the scale to two in every axis. Now let's try it. And we can see when the player is reaching the spinning monster, the most are 88 and its growth. So this is working nicely. So we can see the scene variables are very powerful if we want to use them on many game object for just if the variable is very essential to the scene. Now, the other type of our variables are the up variables, and they are basically similar to see invariable read one big difference. They could also share informations between different scenes. So for this test, I also created second scene called final scene. So first, let's save this current scene with control plus S shortcut. Now let's open the final scene by double-clicking on it. And this scene is super simple. We're only the main camera, directional light and a UI component. Which are cameras and even systems. Now when we open the canvas, we can see also the text Mesh probe text. Now let's create a new empty game object and let's call it text manager inside, Let's create new visual scripting script machine. And I change it to embed. Let's delete the update event because we will be using the start only. Now we are already using the text image pro assembly inside the visual scripting. So to set our text, Let's create a new note heads, right, you go, I said text and let's pick the last one. Let's connect the flow. And now we need to grab our text from here, our H0 to the set text node before we define what it takes to be would like to show when our scene starts proof, Let's click on up variables and let's create new one, and let's name it final scene and text. And let's press Create a change the type to string and also bring it to our graph and connected with a set of things. Now if we test the scene, we can see the text is empty, which is correct. Let's save the scene and we can go back to our first scene called level one. Let's open the monster graph hand we want, when we lost our game to open our final scene, he did text of the capsule name, which is basically monster. Hence, it is valid which killed at the player. So first let's set the text inside our variable. Now to define the text and its create string format the node with the one argument and how to use the name of our capsule. It's Create Game Object, get the name node, and let's connect it with our argument. The string format is very useful note, because it can place this argument anywhere in our text. So in the text field, right, you lost. Then we want to put our argument here. So let's write left curly bracket, then 0, and then write curly bracket, which will be basically replaced with our argument, which will be the monster name. And then let's continue with the killed you exclamation mark at hand. Let's plug it to the set application variable. Now we would like to change C into the final scene. So let's add a scene manager. Lot seen an old Hamlet speak the valve, either seen a name parameter. Let's connect it. Hi, Let's select our final scene and slowly double-click on it, like we would like to rename it. And then just copy the name spaced in bake to the load seen node. And let's ride. But we can see when our player reads the monster, nothing happened. And it is basically because we are missing one important thing to open the scene by visual scripting or even by a C-sharp script, prefers need to add the scene inside the build settings. So we need to open the file. Let's click on the Build Settings. And now we need to select our bot scenes and we need to drag and drop them into the window. And now we are good. So let's close it. And let's try it again. And how you can see when our player will reach the monster, the new scene will open with the text. You lost more circled you. So these working rate, and it is exactly how we wanted. And by this, we also learned how to share values between scenes with the help of the upper variables. Now the last variable type is the saved one, which can be basically saved to our hard drive or the different storage. And it can be reused after return of our game and later returned it back. So it is very useful for saving, for example, high scores are some important progress values. Now to test it, let's click on a saved group and let's save how many times how our monster killed us. So let's write killed count and press Create, hand. The type will be integer. And what do we want? His every time when the Monster ate us, we want to increase this value. So let's make some place in our graph. Let's bring the killed count variable for setting it. Headlights connect it to the flow hint to add some number to the current killed count, we need to first get the old value. So let's bring it to graph to getting it. And let's create a 8-note helots big the second one. And let's connect them together. To show this value inside our game, Let's create new UI text Mesh protects game object. Now let's create a start event because we want to show this counter always. When the game starts. Let's create Hugo. I set text note. And let's connect it with our text layer. Let's connect it with the start event flow. And now to show our counter, we need to bring the saved value to the graph can because its type is integer, we need to convert it to a string. So let's create integer to string note, and let's reconnect them also be the set of text note. Now let's try it. And we can see first time this value is 0. But when we play again, this value is already done. Now, when we check the saved variables, also we can click on a saved values. And here we can see the value is two, which is basically correct. And for example, if we want to test our gain from beginning, so we want to reset the saved value back to 0. We can do it here. So let's do it. And again, let's try it. And we can see we are starting from 0 again. That's basically everything for this lesson. Now, I hope you understand the variable types even more. So. Thank you, and I see you in the next lesson. 9. Embed vs Graph Source: Welcome. In this lesson, I will show you the differences between embedded and save the graphs which we are setting all the time when we are creating new visual scripting rough. Now here we have a simple scene where we have a cube, a sphere, and inside a Canvas we have takes mesh bro text. Now let's create new game object, which will show the distance between our cube and a sphere. And it will show it takes game object. And because we'll be setting the embedded graph there, Let's call it show the stance n-bit. Now let's add a new script machine on it. Let's change the graph source to ambit, and we can see these two events. And let's delete the star one. Now for calculating the stance, we need a scene reference of our cube game object. So let's drag it and drop it to our graph. And we want to use a position so we can directly get it by clicking on the Transform Group halide speak the get position note. And we can see the note is already filled with our cube reference. Now let's do the same for the sphere. Let's go to the Transform Group and let's speak that get position note. And now to calculate these dense plates, create a distance note and let's speak the vector 3 1. And now we can connect them. Now we need another node, which we'll show that these stance to our text component. So let's write you go, I said text and because we are already using thick smash bro assembly inside a visual scripting properties, we can see all these notes. So let's pick the one without the parameter. Now let's connect the flow and also lets calling the set text note with our actual text game object, my grabbing it on the note targets lot. And to connect the distance, we need the float to string out. Let's connect data land, and also let's connect it to the set text input. Now when we test it, we can already see that the stance and even move our cube that the standard text is updating. Now to test and the saved the graph. Let's first turn off this game object so the graph will no longer be evaluated. And let's create new one, and let's call it show the standards graph. Let's add new visual script machine. Hey, let's keep the source on a graph hand. Now we need to click on this Create button. Inside new window, we need to define where we would like to save. This graph has a separate asset file. So let's keep the directory and let's say that the name to show this dance, and let's press the Save button. Now again, our graph have a two events by default. So let's delete the star v1. And, and now let's try to create the same graph P was creating in our hamburger example. First, let's create these towns. Note the vector 3, 1. And also let's create UI set text note the wind without parameters. Now let's connect the flow. Let's create a float to string node. Let's connect them together. So far the graph looks the same. Only what we are missing is our seen references to our game object. So first let's try to connect our text and we, the set takes note and we can see, we cannot do it. We only see the cross symbol. That means this is not possible. And even when we try the same thing only with a cube, it is impossible to bring it inside our workspace. And this is basically the main difference between the saved graph and the embedded van. So now we know that the embedding Graph can use the same references by the saved one, not so the only option how to bring game objects, this saved graph is by using the variables. So let's click on the object type and let's create first one. And the name will be my text, and let's create it. And when we are selecting the type, we can either choose a game object or we can use the component type. And for this case, let's use the company in type, which is that takes mesh, bro, you go, I type an a. Now we can finally drag and drop our text to the variable. And then we can grab our variable and we can use it inside our graph. So let's connect it to the set text. Note for our two game object, we need to create first queue variable, which will be the game object type. Headlights assign it. And for the sphere, Let's do the same. It will be the game object type. Hamlet's assign it as well. Now let's bring the cube to our graph and let's create a new node called good position. And let's connect it also with our distance, a input. Now let's get a sphere. Let's duplicate that good position note, and let's connect it with the distance input B. Now, when we test it. It works exactly the same, but it is a lot of work to do it this way, but sometimes it is necessary. There is a steel big advantage of saving our graphs as a separate asset. We can easily reuse them the inside other game objects to show you, let's disable our last game object. Then let's create new empty one. Helots, call it taster, and let's add new screed machine on it. And instead of clicking on the New button, Let's click on a target icon. And here we can see all our saved graphs, but we have only one. So let's pick that one. And now immediately our graph looks the same in our last game object. Only the thing is, when we tested it doesn't work. And it is because in this case, the graph is depending on a variables which are not set up in this game object. So we need to recreate it first, and we have two options. We can do it manually, or if we have it already somewhere in our scene, we can select that game object. We can go to the variables context menu, and let's click on Copy Component. Now let's go back to our tester game object. Let's click again two variables. Context menu, headlights based the component values. Now the values are there. And when we tested, everything works again. And it is still good. This saving options exist because you can always reuse your graphs inside other projects. Now there is also one advantage of using saved the graphs when we, for example, delete our screed machine component, and it is an n-bit graph. We lost our graph wherever the saved graph is always stored in a separate asset. So to lose it, basically we need to delete the asset itself. Now let's do another test. Let's select our game object. We saved the graph and let's turn it on. Let's press play. And while we are in a play mode, Let's add a new string format note head. Let's connect the flow to string node with the argument 0 panel. It's right inside the text field. These towns then left curly bracket 0, and then the right curly bracket. So our argument 0 will be shown after our text and let's connect it to the side note, I also forget the space. And also let's make the tick size a little smaller. But now we can see our graph is working. And also when we turn off the play mode, all the changes we made inside our graph are stored, which is pretty good thing because we know HIV, we are making any changes inside a game objects in here are HE? The changes are never stored in a play mode. Now let's stays the same on an n-bit graph. So first let's turn off our saved version here. Let's turn on the n-bit one. Let's press play. Hamlet's pay the same changes. Now, if we turn of the play mode, HENI, we check the graph, we can see the changes was not saved. To always remember, play motor changes are saving only for the saved graphs. Now the last thing I would like to show you is how the prefabs works with the embedded graphs. So first, select our cube, helots out the new screed machine on it. And let's make it ambit. Ideally the start even and let's create a rotate around. Note. It's calling them keep the rotation point in center of the vault, change rotation axis. He invited to one and angle 25, and also evolved the cube to rotate around its axis. So let's create a good position node. And let's plug it to the point input. Let's press Play. And we can see it is working. Now let's copy the graph. Let's select our sphere and let's create a new script machine. And this time, keep it as a graph. Let's save it. Let's call it rotate around, whereas delay the start event. And let's base the graph here. Pellets are reconnected. Now when we try it, we need to look closer, but they are both rotating around their centers. So basically now we have a cube with the NBA draft and we have a sphere of either save graph. Now let's create a prefab first from the sphere. So let's drag and drop it into the asset folder. And we can see the sphere prefab was created. And now to test it, Let's bring the prefab to R Here he and basically everything is fine. And I can also re-opened the graph and it is working normally. Now let's select our cube with the embedded graph, and let's try to create a prefab from it. So let's drag and drop it into the asset folder again. And we can see the queue prefab was created normally. But when we drag and drop it to the scene, we can already see our whole graph is deemed. And also we have some warning that the graph is disabled on a prefab instances, so we can't edit it here in here are HE? We only can edit it on a prefab itself on the van, which we placed inside the asset folder. But sometimes I use this approach, for example, for exporting game object with the embedded graphs as a brief ups. But later, I need to remove the prefab reference from them and we can do it easily. We just need to right-click on a game object, then select the prefab menu. We need to click on an ampere completely. And our game object will no longer be a prefab. He'd lost the blue box icon. And now we can also modify our n-bit graph as we wish. And even if we tested, everything is working. And this was basically also everything for this lesson, I wanted to show you, I hope you'll learn more about the differences between the saved and embedded graphs. So thank you and I see you in the next lesson. 10. SuperUnits (Subgraphs): Welcome. In this lesson, we will be talking about a super units or a subgraphs. In our scene we have a cube selected. So let's add screed machine component on it, like change the graph to embed helots Dili the start event. Now let's create the rotate around the node, let's call it did with our flow. Now to rotate our game object from the center, we need a good position out, hey, let's connect it to be the point input. And we would like to rotate it by a five degrees. Now to rotate it in a random access over time, first we need some node, we just incrementing value every frame. And if we think about it, basically the time also doing the same thing, it is increasing forever. So let's add a new node and let Jake this time group and let's speak, good time since level load, we will start from 0 every time we start the play mode, and then it will be growing every frame. Now for changing the axis, it would be good to use only values between one or minus one, which will be the rotation in opposite direction. And for this one, we can use the sign note, which we'll output always a number between minus 11. So let's create it. And if we connected with our time scenes level load, we will get a nice gradually oscillating number between minus 11 and that's what we want. Now, our axes input need a vector three type. So let's add new create vector 3. Note, and let's use these one with X, Y, and Z parameters. Let's connect it. And also let's connect it with the x's. Now, let's tested and we can see cube is rotating, but sometimes it's suddenly changed the direction, which I don't like. But we can see the number from sine is always between minus 11, which is correct. Now to make it nicer, Let's make a little space. Let's create up note, and let's pick the second one. Because there we can change the second input directly. Headlights connected with our sinus node and also with the y-axis of the create vector 3 node. Now the y-axis will be little offset it hand to offset that the z axis as well. Let's do the same thing. First. Let's duplicate the other node. Let's connect it to be the sign, and let's connect it to be the z-axis. And let's change the value to two for a better offset. Now let's try it. And we can see the rotation is much nicer. And I like it a lot more. It's pretty good. Now to store this functionality. We can make a subgraph or a super unit from these nodes. Into doing it, we first need to select the nodes we want to include in our subgraph. Let's cut the selection, for example, with a control and x shortcut. Then let's create a new node and let's go to the next thing, group, Hamlet's click on the super unit. Now to open it, we can double-click on it. And let's click with the right mouse button somewhere in the empty workspace. And let's click on the Paste in our nodes are bake. We need to reconnect them with this input and output and outs, which belongs to super unit. First, let's select the input node and let's make a new flow connection. And the flow connection we can create inside this trigger input. So let's click on the plus button. Let's define a key or basically the name of the input, and let's ride in. Now remember, always when you variety in your input or output name, you need to press Enter because the note will need to initialize. So let's do it. And now we can see the input node has a new flow connection called in. So we can connect it with the rotate around node. Now let's select the output node. And here let's create a trigger output. Hamlet's call it out. Let's press Enter and let's connect it with a rotate around output flow. Now we need another input, because if we want to define which game object we would like to rotate outside of super unit, we need to specify it as an input. So let's click on the input node this time let's create new data input. And let's call it to rotate presenter. And now we need to scroll down and specify the type, which in our case will be the game object. And we can see it inside the input node. And first, we need to reconnect it with a target input and also with the get position input. Now let's go level up and we will do it by clicking on the Q button here in this menu. And we can see here the initial update event and also our new super unit. But right now, when we look at our super unit, the two rotate node must be connected only from the input. We would like to do it also directly from the slot, so we don't need to create new nodes for lead. So let's go back to our super unit by double-clicking on it, selling the input node, let's scroll down until we see our game object input. And let's check this checkbox which will enable default value. Or Basically it will show the targets lot. Now let's go back and we can see in the slot here, and now we can plug there directly what we want. So let's try it first. Let's connect the flow, then minimize our graph and let's connect the cube inside a slope. Let's press Play. And we can see it is working nicely as before. Now in our scene IDs able to these two game objects. And we can see we have a new capsule and a cylinder. What do we want is to rotate them with the same super unit. So let's duplicate our super Unit Two more times. We can connect them one after the other with the flow. And it's also assign a game object to them. First capsule and then cylinder. Now press Play. And we can see they are rotating exactly the same, which is correct. But it would be nice if we can offset that the rotation per each game object. So let's go back to our graph. Open our first super unit, select the input node, and let's add new data input. And let's call it offset, press Enter, and let's change the type to be float hand to use this offset, Let's move our time note to the left, and let's create another other note. Here. Let's connect them together. We can use the B slot, it's fine. And the a slot, let's connect with the offset input. Now let's go back. And this is really weird because our offset is only visible inside the first super unit and we don't see it inside the other two. Even if we open a second one, our offset input is not there. So basically the super units are not the same. And the problem is when he was creating our super unit, we kept the source on the embed option. So we need to remember if we duplicate ambit super unit and later we will change one of them. The second one will not be updated. Now to fix it, we need to save the super unit as a separate asset and to not lose our graph which is inside, we can just click on this convert button and the same window will appear immediately. And let's save it directly here. And let's call it rotate over time. And let's press Save. And now we can see our super units source changed to graph, and the graph target is pointing to our saved asset. Now to reuse these graph also for the other super units, Let's select the second one and now don't praise the convert button, but only change the source to graph, then this window will appear. So let's click on the switch button. Now we can see we have some rate connections, but let's don't care. Let's just click on a target graph and let's choose our rotate over time and the connections are good. And let's do the same for the last super unit, or let's just delete it. Let's bring it in a different way. Let's add new unit heads, right? Rotate over time in our super unit is here. So let's click on it while it's recording the flow. Now let's assign again our game objects for scalps. You'll then cylinder. And now to add some offset, Let's create flow literal. And let's connect it to our first super unit, and let's change it to 10, for example. Then let's duplicate it connected to our second one. I'll change it to 15, then duplicate it one more time connected, and let's change it to 22. For example, Hamlet stride. And now we can see the rotation of every object is different and it looks much better. And this is basically everything for this lesson, I hope you learn something more about super units. So thank you and I will see you in the next one. 11. Debugging Graphs: Welcome. In this lesson, we will be talking about debugging our graphs. So in our scene we have a simple cube. Then we have another game object called Object Controller. And this one has a screed machine, which is rotating our cube in a random direction. So if we tried, we can see how it is working. Now let's create start event, which will delete our cube after three seconds. So let's create destroy game object note, and let's pick the van with a t input. Let's connect the flow from the start. Even then, we need to assign R cube to the objects lot, how it changed t value to three seconds. That means we will be destroying our cube after three seconds. Now let's right, and let's watch our graph. And after three seconds, r cubed disappeared. But our flow still wants to evaluate the nodes, but one of them is red. And also we are getting the error inside the console. And we can see more if we open the console window hand, if we click on the error, we can see the problem game object appeared with a yellow bag around the label for a second. So we know that the problem is going from this game object and it makes sense because our screen machine is attached to it, then we can open the broken graph, but we have it already open, so nothing changed. Now the problematic note inside our broken graph will be the red one has we can see, we zoom in. We can also see what is the problem. And it is written missing game object, which was using inside is note, which makes sense because we just destroyed it. And when we select the note, we can read the error. But it doesn't tell us that much. So let's try to read it inside the console, which also doesn't tell us something more. So let's try to read the error in the expanded window. And finally, we can read that the transform has been destroyed by the, you are still trying to access it. You should check if it's null or you should not destroy it. So let's try to do what is written. Let's create a new node and there is a normal group. So let's open it and let's pick the node, check node. Now we want to decide what do we want to check if it's north? And you want to check if our cube will be known or note after we destroyed. So let's bring it to our graph. Let's connect it with a no check. Hell, it's connected also with our update event. And then we want to rotate our cube only if it's not null. So let's connect the note no branch to the rotate around note. Now we can try it. The error of the recitative. And now after three seconds, we can see the cube disappear in our graph, doesn't have any error. And when we zoom in, we can see the update even is still evaluating mother flow is stopped with the NOR check node. So this is working rate in by these. We also finished this lesson. I hope you learn something more about debugging your flow and also about null check node. So thank you and I will see you in the next lesson. 12. Graph Reevaluation and Cache: Welcome. In this lesson we will be talking about graph re-evaluation and occasion hold. Now we have a simple scene with a sphere which has a screed machine component. We the n-bit graph. So let's maximize it. And what we want is to change sphere scale by random number every time we start our game. So first, let's delete the update event. Hell, it's create set local scale node. Let's connect the flow and forgetting the random number. We can add new random dot range. Note, Let's pick the first one. Has it changed and max random number to three. So we will be always getting random number between 032. Plug these random number to our scale. We need to create a vector from it first. So let's add a new node and let's write create vector. And let's speak the vector 3, we the XYZ inputs. And let's connect them with a random node and also connect them with a set local scale. Now before we try it, first, guess if everything will be fine because it looks, it should be. So let's try it. And we can see the sphere changed the scale, but every axis received different random number even if he was using one random node. And we can see different value also in a graph. And we need to remember if we are using same note, but a node has multiple connection inside the same output, denote will be evaluated for each output separately. So that's why we have different values for different x's. Now to deal with it, we can either create a new variable, like a random number. And let's bring it to the graph to set it. And then we can connect it with the random and also with all the axes directly. And also let's don't forget to connect it with the flow. Now let's try it. And we can see the sphere is receiving same random number for each axis, which is what we wanted. But there is also another way which it doesn't need to create any variables. So let's delete our variables. And there is a special node and it is inside a control group, and it is called cash. So let's connect it to our graph, exactly how he was connecting the variable. And it is basically doing the same thing. It is a saving result and then reusing it without the notary evaluation. So let's test it. And we can see it is working as before, and that's basically everything for this lesson. So thank you and I see you in the next one. 13. Reduce Graph Size with Control Nodes: Welcome. In this lesson, we will talk about how we can refactor our graphs so they will look much more cleaner. So we have a basically simple scene with the cameras parent, where we have our blue background image and a text mesh for our text. Now select our image and let's create new script machine. Hello, change it to embed, and let's delete the default events. Now let's maximize the graph. Now what we would like is to create some graph which later we will be cleaning and optimizing. And basically this graph will be solving simple task. It will just show the text which mouse button we are clicking. Now to start, we need to create first pointer click event. So let's go to events, then to GUI. And let's use on-point arrow click event. Now let's create the last node in the flow, which we will be setting our text. So let's write Hugo I said text. And because we already added, takes much pro assembly inside our visual scripting properties, we can see all these nodes. So let's pick the last one without any parameter. Now let's connect our text game object to the set text note. Now we need to find a way how we can decide which mouse button we are clicking. So let's drag the event data output a little bit to our work area. And we can see the output is called pointer even data. So let's open it and let's use these node called gate button. Now, if you look inside the graph inspector, the output of this node is a input button of pointer, even data. And because the color of this output is being, we should remember this is an enum type and basically all the enum types inside visual scripting has this pink color. And now because we know it is an enum type, we can compare it with the same non-literal where we just select different options which we would like to compare. Now for comparison, let's create a new node. Let's go to the logic and let's pick the equal note and we can connect the gate button and old me the input a. Now we need the actual inner literal. So let's write the same name we see in the output. And let's start with the input button. And if we scroll down, we can see there is our enum. Read the full name. So let's be good. Now we see the NM have an options we needed, which are basically different mouse buttons inside the drop down menu. Right now, let's keep it on a left button. Now let's connect it with a competitor node. So we are basically asking if the button we are clicking will be the left mouse button, and then we can decide what to do next. Now for this decision, we need to create evil node. Let's connect it. Now we can connect the true branch with our set text note. And also we need to connect the event flow. Now to set text which button we are clicking. Let's create a string literal. It's connected and inside, Let's write left. Now to test if we click the right mouse button, let's select these five unknowns and let's duplicate them with a control and D shortcut, headlights connect AND gate button output and also its connect first IF false branch B, the second even odd because if our mouse button is not left, we need to check the other option. And now let's change the second literal to right. And also let's change the text to right. Now for the middle button, Let's do the same. Let's select the five nodes. Let's duplicate them. Connect them. Changed the in AMP2 middle, and let's change the text to middle as well. Now we can create a group and let's call it Show button Start. Now we can test it. And when we try it, we can see all the buttons we are bracing inside a game view, which is working correctly. Now let's go back to our graph. And even if this graph is working, it looks kind of complicated to me. So let's try to optimize it a little bit. And for cleaning our graph, we can use these control group varies, a lot of useful notes which we can use. So first, let's try to use switch on integer node. Now let's check what this node is doing. So inside the graph inspector, we have basically option to add some entry. And when we add one, we can see new flow output appeared inside our node. So basically we the switch node, we have option to separate flow by some condition similar to IV note, but in Sweden nodes, we can have a more output then only the two which are depending on true or false. Now let's shake. We have 123 different texts, so we need to add three outputs. Each of them needs to have a unique integer number, which will be basically index of the output. And then depending on the number which we are getting on input, the corresponding flow, it'll be triggered on the output. Now let's copy the six nodes with a string literal and duplicate them. Let's connect them with our switch and out. Now we need to find a way how to plug a number which needs to be 0, 1, or 2, and which will trigger the specific output flow. So first let's go to our first row. It's moved the text notes aside, and let's copy all these nodes and duplicate them. And now let's check again the control group. And this time, let's try to select on flow node. And we can see it has to flow input to data input and van flow and data output. So these note might work. And basically selling nodes in general have a multiple data inputs and they are selecting which of them will be the data output depending on the condition, which in this case is to trigger a specific flow connection on input. But now we need to connect 123 if branches. So let's add three inside the branch count, and let's connect them with a true branches. And also let's connect them together with this region out. Still, we are missing the data inputs and we know we need integer numbers, 0, 1, 2. So now let's make some place. Highlights. Create integer literal node, and it is a 0, which is fine. So let's connect it with our first input. Now I'll duplicate it connected to the second one, and I change it to one. And let's do it again. And let's change it to two. Now to test it. First, let's disconnect the first flow from the event and eerie click on edim button. We can see all these nodes which are not evaluated are transparent. Now let's group our other flow and let's call it version two. Hello, Let's test it. And we can see it is working as well. But I have a feeling we didn't optimize the graph at all. I think we made it much more complex. So let's try it again. Let's copy all the notes and let's duplicate them. Let's disconnect the flow from the version two event, and now let's try to optimize it again. So let's give the select on flow modulates, use it without a switch node. So let's delete that one. Let's also deleted the three integer literals, and let's try to replace them with our string literals directly. So first let's disconnect them and move them closer. And let's connect them again, same order. And now we can see we just need one set text node. So let's connect the first one. And now let's delete the others. Now, I like this version more. So let's group it and let's call it version 3. Now let's try it. And we can see it's doing the same thing. We just great. Now again, let's try to make our graph even more cleaner. So let's copy all the nodes. Let's duplicate them, and let's disconnect the flow from the version 3. Now, when we click on our button, the output is enum type. So let's try to create switch on Inner node. So let's go to control. Let's pick the switch on enum here let's click on the drop-down halides riders, same in a name. We need. We just input button and we can see it already. So it's Pickett and, and now our switch is already filled with the enum input. And also we can see different flow outputs which are triggered depending on the inner value. So now we can delete all of these if nodes and also the comparisons. And we can directly plug the gate button output to the switch node. Also recollect the flow with an event, and also let's connect them with our select note. We the same order. Let's group these notes and let's call them Version 4. Now let's try it again and we can see it is doing the same thing. And also our graph looks much cleaner. Now, I think we can do even better. So let's duplicate the notes again. Let's disconnect the version four. And now let's try to select on Inner node also, let's select the drop-down menu and let's find our button, NM input button, and let's pick it. And we can see the celiac node has pre-filled inputs. We the inner options. Now let's select our string literals here, Let's duplicate them and it's calming them directly with the select note. Also connect the gate button output, and let's delete all these nodes. And let's reconnect all three flows with the setText note. And also connect the select output to the set text input. Now group the flow and let's call it version five. Let's try it. We can see this working exactly the same. Now let's finish it with a final optimization. Let's duplicate the nodes. These connect the version five flow. And basically what we can see is that the switch node is always triggering the set text note, no matter which button we are oppressing. Basically this is unnecessary and we can delete it. And let's connect the flow directly from the onclick event. Now let's group the notes and let's call it final version. Let's try it. And we can see it is working the same. Now let's check back our graph and we can see if we have made six different version, you the same functionality we started with this first one. The enemy was added more nodes, we was not great. Then we were starting to cleaning it more and more. And at the end, we end up with this final version. So we can see basically nodes could look a lot bigger, but there might be options how to optimize them can be much more readable. As a bonus, I will show you that we can optimize our final graph even more. We can see the enum values have the exact same name, which we are using as a string literal. So basically we don't even need to use the select note, so let's delete it and also all the string literals. We just need to convert this enum to the string directly. But there is no enum to string node which we could use. But there is a generic one which we can plug to any node. And it is called object toString. So let's use that one and let's connect it also be the set text note and also re-connect the flow. And let's test it. And we can see our graph works great again. And we have even cleaner flow then before. And by this, I would like to finish this lesson. I hope you'll learn how to clean and optimize your graphs. So thank you and I'll see you in an exam. 14. Events: Welcome. In this lesson, we will be talking about events. So in our scene, Let's create new empty game object and let's call it game manager and lights up new screed machine component on it, how it changed it to embed. And we can see her right from the beginning. We have here two events. First is a start event, which will be triggered when our game will start. And then we have update event, which is triggered every frame. Now let's delete them. It's opened a fuzzy finder and we can see there is one whole group called events. And when we look inside, there are lot of events separated in a specific groups. So for example, we have animation EVA, and then we have application events like when we quit our game. Then we have some editor events which are working only inside editor, so we don't need to run our game to trigger them. Then we have GUI events like on button, click or on-point down, and then we have a lot more. So for now, let's create a new one. Let's click on an input group and I choose own keyboard input, which basically is triggered always when we press down our space key. And we can test it by changing our text. So let's add new node and let's write uy set text note. And because we are already using that takes mesh per assembly inside the visual scripting, we can see all these nodes. So let's pick the one without parameter whole. So let's create new string literal, connect them together and I change the text tool you want with an exclamation mark. Households don't forget to assign R takes game object. Now let's select our flow and let's duplicate it. Let's change the action to up to basically we are triggering this event when we are really seeing the space button and we want to change the text to be, you lost with an exclamation mark. Now let's test it. And we can see every time we press our space that takes changes to you when solids hold it for a while. And then when we're really is the space that takes, will change to you lost. Now, when we are developing real game, we don't like that. We are changing the UI inside a game manager. We would like to use, for example, UI Manager for this. So to test it, let's create an empty game object and let's call it UI Manager. And let's create new screen machine on it. How I change it to ambit. Let's delete the two events and let's go back to our game manager. And let's select these four nodes. Scattered the selection with a control and x shortcut. Let's select our UI Manager and let's paste our note there. Now let's maximize the graph. Now, we don't need these two set text notes, so let's delete one of them. And to create the same functionality, let's add new control, select note. Let's connect a string into the true and false inputs, and let's connect the select output. We set text note, now we can see the celiac node needs some input, which we'll decide if we will show the win or lose texts. Now inside our game manager, we will be still triggering the keyboard events, but bake in our UI Manager, we still want to use them. And for this case, when we want to use events from different game object, we can create special event, which is called Custom Event. Henry can see there are two nodes vanishes for triggering this event. And the second one is for defining it. And in our case, we want first to define it. So let's speak the custom ear and note. Let's connect the flow with our set X note. Then we need to set the name of the event. So let's call it update win-lose text. But now it would be nice if we can also connect it with our silicon hold somehow. And right now, our event doesn't have any output value. But luckily we can change it, read his argument number. So let's change it to one. Now we can see our event has one output. So if we will be using it as a Boolean, we can connect it to our select note and it should work. So let's do it. Now let's go back to our game manager. And here Let's create a new note. Let's go to events. And now because we want to trigger our custom event, let's pick that trigger note. And to connect them together, virtually, we need to call it with the same name. So let's go back to our UI Manager. Let's copy our custom event name and let's paste it back to our custom event trigger. Then we need to fill these targets lot. Because if our custom event is defined in the other game object, which in our case is, we need to also assign it to the slot. So let's do it. Let's grab our UI manager game object and let's drop it to the slot. Last thing, we need to check how many arguments has outrigger. And we can see it has 1. So we need to change the argument value also to one. And now we can see the trigger has one more input for our argument. Now we know that our argument needs to be true or false. So let's create new node. Let's go to Control Group and let's pick the select on thrown out. And let's connect our flow from the event me, the inputs a and B. And let's connect the data output with our argument and also the flow. Now to define our data, let's create new Boolean literal node. Let's duplicate it. Let's connect the second one with a slot B and the first one with the slot a, while I change the value to true. Now this should work. So let's try it. And we can see if I press the space, I see when text him when I release it, I see the lowest. So these working perfectly. And we also learn how to use a custom events. And it's basically everything for this lesson. So thank you, and I see you in the next one. 15. Collections and Loops: In this lesson, I would like to talk about collections and loops. So in our scene we have a cube and we would like to change its color with a button. So let's create new UI button, takes mesh, bro, let's import that takes much pro essential files. Now let's change the button text to update. Now let's create empty game object and let's call it UI Manager. And let's add new script machine on it. And let's change it to embed. Also, we can delete our default events. Now to change color of our cube, the easiest way is to change the material which will have a different base color. And I just prepare three materials inside the material folder. And they are green, orange, and red. Knob. Let's select our UI Manager. Let's create a new event, an insight GUI, speak the Owner button and click one. Now let's assign our button game object to the targets lot. When we select our cube, we can see there is a Mesh Renderer component where we can add new material. So inside our graph, Let's create new set material node and it's big the Mesh Renderer one. Let's connect them together and let's set it with our cube game object. Now to work with our three materials, or basically any other game object or values advance, we can use a new variable type, which is called list. So let's create new object variable with a name list of utter chaos. And let's click on Create. And for our type, Let's write leased space material, and let's pick the first one. Now we have a possibility to add the new entries to the list by clicking on this plus button. So let's do it. Bounce buys one more because we have three materials. And, and now we can see that the list is basically a collection of values which could be accessed by its index, where first item has index 0 and the last one has a index 2. Now let's assign our materials to these three slots. Now working with the list variable is the same as working with any other. So let's bring it to our graph. We just need to drag and drop it there. But the difference is if we want to do some operations on the list itself, we need to use special nodes and they are here in the Collections group. And here already we can see some notes like count items, first item or the last item, which are basically self-explanatory. And also inside the list group there will be lot more notes. But for now, let's use the first item note, and let's connect it with our variable. And also let's connect it to be the set material node and what it is doing, it always return the first value from our list, which in our case is the green material. So let's test it. Let's press button and we can see now a cube is a green, exactly how we expect it. Now instead of first item, Let's use random item. So let's write random dot range and let's use the first one, we the mean inclusive and a max inclusive parameter. And we would like number between 0 and our item count of the list. So to get the discount the number, let's go to collections and let's speak count items. Now let's connect it with our list and also with the random that range max value. And now we can see we cannot connect the random range directly to the set material slot because its output is a number, what do we need is basically to get material from our list, this random index. So let's go again to Collections group, then to the list. And here let's pick the good list item note where we can plug the index and it gives us the item. So first let's plug the list variable to denote how it's connected with the random range note. And finally, let's connect it with our set material node. And now we can try it. Let's press the button couple of times and we have random material peak almost each time we press it. But when we are doing it little longer, we will get an error. And when we check the value from the random node, the value is 2.76, which is basically rounded to three. And the true is we have three items inside the list. Now the first index is 0, second index is one, and the last index is two. So that's why we are getting error. There is no index on our number three and you recheck in the console, there is also written that index is out of range. We just basically the same thing. And if we remember that we were choosing from the two random range, note The second one would be the better option. So let's delete this one and let's create new one. And let's write random node range three can see both of them. And insight second one, there is written max value exclusively, and that means this value will never be reached in opposite to the inclusive option. So let's pick this node and let's reconnect it. And now even our max value is connected to the item count, which is still 3. We will never use three for calculating the random number. It will always use two has a maximum index. So let's try it. We can click on the button as many times as we want, but we will never see the error again. And also, if we check the value of our random range, note the number is never higher than two, which is what we wanted. Now let's make different setup, which will create one new box for each material in the list. And also we will assign this material to this box. So let's do it. Let's delete the random range. Note. Now the easiest way how to create one cube bear material. We can loop over these lists. A special note. So let's go to the control group. And here Let's be for-loop note. And we can see we need to specify first index of the iteration which will be 0. Then for the last index, we can use our count item note, because this number is x equals 0, so we will not get the error and we want to loop over each index one-by-one. So let's keep the step value to one. Now let's disconnect our flow from the button click event, and let's connect it to the for loop. Now if we want to create new game object like our cube, we need to use instantiate note, and let's pick the one with the position and rotation or load. Now to instantiate one game object pair, each loop iteration, we need to connect it with the flow from the body output. Now we need to define what we want to instantiate. And we know we want a cube, but we need to remember if we are instantiating game object, we always have to use prefabs because otherwise it will not work. So to create brief up from R cubed, first open the project window and let's drag and drop our cube inside. And now we can see our prefab was created. Now let's delete the old cube from here he, Alice assign our brief up to the original slot. Now, the output of the Instantiate cube is the newly created cube. We'd revote also for the material assignment. So let's plug it directly to the cemetery. How input. Now to get the right material, we can use the index of iteration from our for loop and let's connect it to the get item note. And also let's connect it with our material list. Now for each cube, we want slightly different position and we can do it easily. So let's click on Control and let's use select on integer. Now we know we have 012 indexes. So let's create the same numbers inside a select note. And let's drop index value from our for loop and plug it to select note first input. And let's connect select note with the position input. Now we need to define all three different positions. Hamlet's right, create vector 3, and let's pick the second option. Has duplicate it two more times. And let's connect each two different. Select a note input. Hello, change first x-value, two minus three seconds. Let's keep to 0, and the last one will be three. Now for rotation, we don't want any, so we can use quaternion dot identity and let's pick it and also let's plug it and also don't forget to connect the flow to our set material. Note, now our celiac node is still orange because we didn't provide the default value. But we know our index will be always between 02, so we don't need to define it for different values. Now let's try it. And when we press Update button, we are creating three cubes with the same materials as we have in our list. So this is working. Now open our graph and instead of a for loop, let's try to use for each loop, which I like a lot more toward width. So let's go to Control and let's peak for each loop. Now to use it, we don't need some of the nodes. We can delete account item note, then our foreach loop and also get item note, basically these all three nodes can be replaced with one for each loop. So let's connect our list. Let's use item output. Let's connect it with the material. And we can do it because for each loop, have already reference to currently protest item. Then let's connect the index with a select note. And also don't forget to connect flow from the button click event and also connect body flow with the instantiated note. Now let's test it and the result is same. It is working how it should. Now I can show you different collection type called dictionary, which can store values which will not be accessed by index, but by any unique value which is called key. And key can be, for example, string, number, game object or position. And in our case, because our cubes are currently unique positions, we can recreate these graph with the use of dictionary, and it will be a lot simpler. So let's do it first. Let's go to the object variables and let's delete the old list. Now let's create new one and let's call it dictionary of positions and materials. Presenter type will be AOT dictionary and the shortcut a and T stands for ahead of time. Now the side-note, normally in C Sharp language when we are filling the lists or dictionaries, we have to use Van type for the key and Van type for the value. But inside of AOT list, we can use a lot of values with the different types. And similarly, inside AOT dictionaries, we can have different types, four keys, and different types for values. But this is something new and we will not using it inside our course. But it's good to know that the option is here. Now for our key, we will use our cubes positions. So the type will be vector three and the value, let's use the material type. Now let's assign our green material. Hannah key will be position and minus 3 and 0, 0. Now let's add the new entry with the plus icon. Let's assign here the orange material, and let's change the key to 000 000 headlights create another entry. And let's assign our red material, handling, change the key 23 000. And we can see these three keys are unique. But if we try to create N3 with the same key, this window will show up telling us this item with the same key already exists, so we cannot do it. So let's leave it like it is. Now to use our dictionary, Let's bring it to our graph and we can reconnect it directly with a for each loop. But we have to check these dictionary checkbox if we want to loop through the dictionaries. And when we are doing it, we can see there is one more output appearing media key name, which is basically defining our unique position of our materials. So let's keep it checked. Now. We don't need the celiac nodes. We can directly use our key output with the position input. And how we can test it. And we can see it is working as before hand. It is much more simpler. And it's basically everything for this lesson, I hope you learn something more about collections and lobes. So thank you and I will see you in the next one. 16. Script Machine vs State Machine: Welcome. In this lesson, we will discuss the difference of using screed machine and state machine. We have a simple scene with very simplified traffic lights model, which was made basically from three spheres and one box. Now to add functionality to our traffic lights, Let's start with the screen machine. First, let's create a new empty game object, and let's call it traffic lights, screed machine. And let's create script machine component on it. And we don't need the update event, so let's delete it. Now the behaviors of our traffic lights will be first they showed the red color for some time, then the orange color appear together with red, so the drivers can expect to move soon. And then only the green light will show for some time. And then again, the orange light will appear. So the drivers should expect there will be a red light soon, and then it goes back to completely red. And these logic will repeat over and over. So let's start to show a red light first. And the easiest way to do it is by changing the material. So let's create a new node. L is right said material and we need the Mesh Renderer one. Now let's plug our red sphere on it. And also let's plot the red material which I already made. So let's use it. Now to keep it visible for some time, we can use time note, which is inside time group. And to start it, let's connect it from our start event to the timer starts slot. And we can also connect our time started output with our sand material note. So basically when the timer start, we will change the material to rate how to define how long we want our light to be only read. Let's specify the duration to two seconds. Our traffic lights will be pretty fast. Now after I finish this duration, we want to show also the orange light. So let's duplicate the timer node. And when our first timer is completed, Let's start these new one and let's keep the duration to two seconds. Now we want to show orange light. So let's duplicate a set material node connected media started flow, and let's assign orange material firms. And also let's assign the orange sphere. We just the second one. Now let's test it. And after two seconds we see orange lights appear, so it is working. Now after two seconds, we want to turn off orange and red light. So let's copy the set material and let's plug it with completed flow. And I change orange light back to black material. And for our red light, Let's duplicate this note. Let's connect it here. So they will evaluate together and also assign the blame material. Now we want to taste it. And we can see they are going Blake, so it is working. Now let's duplicate our timer again, connected from this flow. So when the lights are off, we are starting new timer. Let's again duplicate the same material node and connect it to the Started flow. And we want to assign our green sphere and also the green material. So let's test it. And it is working good. Now again, to turn on also the orange light. And after two seconds, we want to just turn these two lights off. We can select all the notes and duplicate them. And let's connect them with a completed flow. And we just need to reassign green sphere instead of rate. So let's do it. And now we can try it again. And we can see the main cycle is ready, we just need to repeat it. So at the end of the flow, let's create new custom event trigger. So let's connect it and let's call it star again. And also we need the actual customer even note needs to have the same name. So let's copy the name and let's use it. Let's move this event to the beginning of the flow, and let's connect it with a timer start together with the start event. Now let's try it. And we can see it is working nicely. Mother graph is kind of note much readable and I think we can do better. So let's select our traffic light screed machine game object, and let's turn it off. Now let's create new empty game object. Let's call it traffic lights state machine. And let's create a new component. Scroll down to visual scripting and here, peak the state machine component. And again, let's make it ambit. And now we can ask, what are these state machines? And they are basically different programming architecture by which we can create some high level logic. And even it sounds complicated, they are really easy to work with. And for example, good use of state machines can be to create an enemy a high, their first NMI is patrolling. Then if it will see us, it can chase us, and when he catch us, it can attack. So each state is basically defining different NME behavior. And for changing the state to another one, we are using conditions which we are defining inside the state transitions. Now we can see when we open a new state machine, it has already run a state prepared, we just called start. And on this note we can see which triggers are inside the state. So let's go inside by double-clicking on it. And basically now we are in a state screed machine. That means the states are basically encapsulated screen machines with some more high-level functionality. Now we can see we have some different events, but also we can see the update one, which we already know. And the other events are basically belonging to this parent state, where first one will be triggered when we enter the state and the last one when we leave it. Let's go back to our traffic lights control and we want to start them with a red light. So we need only the interstate event. Hell, It's delete the rest and let's do the similar thing. Let's create sedimentary. I'll note that Mesh Renderer one here. Let's connect them together. Now let's assign our red sphere inside. Also assign a red material. Now go back one level and it is by clicking on the state machine icon inside this menu. And we can see our start state changed a little bit. It is showing that we are using inside only one event called interstate, which is correct. Now when we right-click on the state, we can click on Toggle start and we see the green label, these appear and these green label or showing that we were starting the state automatically. Where do we was running our game? And we want to do it. We want the state to be active when we start playing our game. So let's press it again, and now let's test it. And we can see our first light is red and the label of our state changed to blue. That means the state is currently activated. Now we can rename our state so we know what it is doing. So first we need to select it. And now inside the graph Inspector, let's click on Start name and let's change it to red. Now let's create another script state by right-clicking on a work area. And now we know that we will be adding the orange light by the red will also be visible. So let's change the state and aim to read slash orange. Hell, it's open it. Hello, Let's delete the update event and let's keep the wrist. And now when we enter the state, you would like to change the second light orange. So let's add new set material node. Let's connect it to the interstate. And also when we finish the state, we would like to change the red and orange light back to break. So let's duplicate said Material note. Let's connect it with the exit state and duplicate it one more time. And let's connect it as well. Now let's feel the references. So when we enter the state, we want set our orange sphere with the orange material hand. When we exiting the state, we want to turn off our orange sphere, black material. And also, let's turn off the red sphere with a black material as well. Let's go bake. And now we have these two states ready now to change rate state to our red slash Orient state, we need to connect them with a transition. So let's right-click on a red state and let's click on Make transition. And then we can see this line will appear and we need to just click on other state we want to connect. So let's click on it. And now we can see these new node called transition appeared. By double-click on it, we can see where we can define our condition for changing this transition. Because we want to create timer, we need some event, which we'll start this timer, but only if we are on the state which these drowsy shell is connected from him. Luckily, we can go to the events state group. And here let's pick on interstate and this one will trigger when we enter our red state. Now let's create our dimer. Let's connect them. I change the duration to two seconds and when it will be completed, we will trigger transition to the Connected state. Now let's try it. Let's watch the graph and we can see our red state is active for first two seconds after our red orange state is activated, and we can see the blue label. But the lights did not turn off because we didn't have exited our second state. So we need to create another state. And for these, we can just select our red state and let's duplicate it. And first, let's turn on the Toggle start here. Let's rename it to green. Let's open it. And I change the sphere to sphere green, and also change the material to green. Let's go back. And also let's make transition. Now to make the same condition inside our transition, let's go inside the old one. Let's select our two nodes and let's copy them. Now let's open our second transition and let's paste it and calling the transition with a connected flow. Now let's go back and we can test it. And it is working great. Now to create our last state, Let's duplicate the middle one and let's rename it to green, orange. Now let's open it. And lead, change these last note to green sphere and it's all we need to change. So let's go back. Let's make a transition. It's again copy the old one. L is recollected. And also let's make the last transition and let's paste it also hear how it's connected as well. Now we're done and we can test it. And we can see everything is working. And we can also watch our states, how they are switching. And when I compare it with our screed machine example, the setup looks much more cleaner and much more understandable. So I would prefer to do it this way. And a lot of times when you will be developing your game, you can, you state machines for a lot of tasks. And if you are using them, right, they will make your programming much more easier. And that's basically everything for this lesson, I hope you'll learn something more about differences between scrape test state machines. So thank you and I will see you in the next lesson. 17. Reusable Panel UI Creation: In this video, we will be creating a simple user interface panel with the two buttons, which we will show up when we finish our game. So then we can re-start it or acquitted. And we will try to make it very universal so we can reuse it in the more games. Now these are empty project made from 2D template. So that's why we don't hire or default light in our scene. But it doesn't matter because we will be creating only the 2D UI panel, so we are fine. So first let's create new cameras game object. Now we can see that our karmas is huge. So let's change the render mode to screen space camera. And let's drag and drop our main camera to the render camera slot. And now our Gammas, it's much smaller. Now inside our Canvas, Let's create an empty game object, and let's call it thumbnail, been loose. And let's make our panel stretchable by clicking on a OnCourse icon. And let's press Alt and Shift together. So you will see the same options and I choose the stretching icon. And now our panel is as big as our canvas. And if our canvas size will change, the span L will change as well. Under the bottle, Let's create another empty game object and let's rename it to paneled parent. Now inside here let's create new image component. And we can see our panellists field with a white image while it changes the source images to this, my ground sprite. And we need to change the span L bar and size, but we don't need to use the anchors for it. Be we will be using the bunny hill we lose to control the size of Children's. So let's select the parent panel win-lose, and let's add the new layout component. And because we will be controlling size of only one child, we can choose horizontal or vertical layer group, and this case, for example, it choose the horizontal one and electric control, child size, width, and height, and also change child alignment to middle center. Now we can see the size of our chiral LED panel is controlled by this win-lose game object. Now to create small gaps from all corners of our win-lose. But l, Let's open the bedding and let's add the 50 value to every site. Let's make our panel little around it. So let's select that bundled parent. And luckily our beggar and sprite has a rounded corners so we can make it more prominent by changing pixels per unit LSU, something smaller, for example, 0.07. And now this banner looks much more around it. Now let's create two text objects inside our panel, Barend. So let's right-click on it. Choose UI, and here choose takes much protects. First, let's rename our text game object, two main text. And we can also see these new window appear. And it is because when we are using that takes mesh pro for the first time in our project. Thanks much. Part needs to import some essential files to work correctly. So let's just click on Import button. And now we can pause it. Now, let's duplicate our text and let's rename it to secondary, the inlet. Select our pile Barend and we want to control our two texts, panels, sizes, and positions from this parent. So let's add new layout component on it. And this time, let's choose vertical layout group. Because we want it, our texts will be placed man under the other and also a change control, child size, width, and height, and also change traveled alignment to middle center. Now let's tweak our Takes game object. So let's select both of them and the first leg check the outer size so that takes can automatically grow or shrink depending of the parent panel size. And let's change the minimum size to 0 and the maximum to 132. And also let change the alignment to be in the middle of the pile. Now let's select first stakes game object and let's change the text. And because I know we will be changing the text from our graph, I always try to start the text with some symbol. So later on when I change it by script, I can clearly see that it was changed correctly. So here, let's start with a multiply or a star symbol, and then let's write you lose with the exclamation mark. For the second text lays a variety star symbol. And let's continue with the try again, also with a question mark. Now let's go to the game view and let's undock the bile. And we can try to change the size of it. And we can see if our window, for example, will be on some mobile devices and these thin that takes will be leaking from the banal background image. So to fix it, first of all, it's located back our game view panel. Let's go back to our senior you, and now let's select our panel parent. And let's also add some headings. Hell, it's right to use also the 50 for all sides. Now let's try it again. And we can see it is much better. That takes this always inside a big round. Now you would like to add two more buttons to our panel. So first under our panel bar, and let's create a new empty game object, and let's call it button parentheses. And inside, Let's create new UI button. And let's choose the text mesh program. Let's rename it to the button he is. Now let's duplicate it. And the second one will be the button. Know. Now to see our buttons properly, again, let's select their pairing. Hell, it's other horizontal layer group component. And also Jake control child size, width, and height in change that I made to the middle center. Now, let's 30k our button colors. So first let's select that button is, and let's change the car to green. And also let's make the button more rounded. So let's change the pixel bear. You need to 0.2. Now if we want for our second button to hell, same settings, can easily click on this context menu and let's click on Copy Component. Let's select our button now and go to the same context menu, embrace base component values. And we can see that both buttons have the same color and also same surroundings. Matlab change the color to red. Now let's open our ears button and change the text to yes. It's also check out those size and let's change the mean to 0 and max 252, and let's change the color to be white. Now let's copy the component. And let's base to the settings into NOW button text. Change that takes to be no. Now we can see the buttons are too narrow. So to fix it, first switch back to our scene view. Now let's alike all three childrens of our parent bile. And let's add the layout element component. Held a change, prefer it hide to be 200. And we can see our board depths and the bottom part and have the same proportions. Now let's check it from our game view. And we can see it is working. Only the text inside the buttons are leaking little bit, but only when we have very thin view. So to fix it, played select both buttons. Elites, how did they or another layout element. And we can use horizontal or vertical layout group might lead choose horizontal. And it's also chick, control, Charles size wheat and hide, how they change left and right padding to 10. Now we can see that it takes, is always inside the buttons, but to be safe, let's also change padding for the top and the bottom to 10. Now, if it's too narrow, it will not work because the size will be 0 anyway. But if we will check the real world example, let's click on the Free Aspect and let's choose some landscape, full HD resolution. And this is working nicely. And if we switch it into the board trade one, it is still working fine. So let's dock our game. You bake, and switch the resolution to free aspect again. And also let's go back to our scene view. And that's everything for this lesson. So we will continue in next one. 18. Reusable Panel Script Machine: Now we would like to add some functionality to our buttons. So let's select a win loss parent and let's add new visual scripting screed machine on it, change the source to embed helots. Click on edit graph here. Now because we are opening visual scripting first time in this project, we need to wait until it initialize. Now you can see the span L. So let's dock eat first and let's resize it a little bit. Now we don't need these two events, so let's delete them. Now we need to add events for our button clicks. So let's right-click headlights, go to the events, then to the GUI. And here let's pick on button click event. Now let's duplicate it with control plus D. And now we need to fill our buttons. So first let's rock button yes, to our first event slot. And also let's drag and drop our button now to the second event slot. Now when we click on our button and we would like to add functionality to resit our scene. The easiest way how to reset it is to somehow reload our currently open scene. So for this, let's add new note and let's ride scene manager Claude scene. And let's pick the second one only with a senior name parameter. And let's connect the flow with our first button. Now the question is how we can get the current seen her name. And for this, we can use another node called good active scene. My du. We can see the output of this node is not a string. So we need to convert it first. And for that we can use the different node called seen and get a name. And let's connect them all together. Now we can group our first button notes, and let's call it re-start game. Now for our second button, we would like to quit our game, Hannah, for these, we can use simple note call application that greed. Hey, let's connect them together. It's also group them and let's call it quits game. Now let's save our game. Hello, it's tested. So press Play. Now let's press this button and we can see the scene was resurrected. And when we press know, it seems like nothing happened. But it is only because the application quit is not working inside Unity editor. It is only working in the bill that game. So right now, we need to trust that it is working. Now we need to create custom event, which will change our panel text based on our game state. So that means we would like to see differ at text if we win the game and different taste if you lose it. Inside events, let's create a custom event and let's call it started me. And it will have one argument. And it will be a Boolean value, which will be defining who we are winning or losing. Now for setting our text Mesh bro, text, Let's set fixed note. But I know we don't have it inside our finder, so we need to add it to the visual scripting. So let's click on Edit panel and let's select the project settings here Let's click on visual scripting opened Node library. And we need to add a new assembly. Hell, it's right, takes much Pro and it's added. We need to regenerate the units. So let's wait awhile. Now let's go back and let's add a new node and a variety of Uruguay, say that text, and I choose the last one. And because we have two texts, let's duplicate it and let's assign them to our notes. First, let's assign main tags to the first node and then secondary texts to our second node. Now our custom event argument will be true or false. So we can use the select note and let's connect it with the argument. And now let's create a string literal and let's connect it with a true input. And if we are winning the game, argument will be true and the tags will be u1. And for the losing, Let's duplicate a string and I change it to, you lose. And let's connect it to be the false branch. Now let's connect our celiac node with a first set text note. Now for our second things note, let's duplicate a string literal one more time. And I changed it takes to play again with a question mark. And let's connect them. And also it's calling the flow from our custom event to the first set takes note and foreign debt down to the other. Now let's group the note and let's call them, say, the main and secondary texts. Now to test it plays right-click on our canvas. And let's create a new text mesh button. And let's call it button amine. Let's say like Did everyone to align it better in our Canvas? So click on anchors, icon and press Shift and Alt and align it to the corner. Now open the button and let's change the text to try when it's duplicated. And let's rename it to button laws, and let's align it to the opposite corner. And also a change takes to try lose. Now let's select our button when Hamlet's make script machine on it. Please make it embedded. Now let's delete the Events Highlights, create new event GUI, electrons on button click. And because the screen machine is already sitting on the button, we don't need to plug it because the keyword, this is referring to the button game object itself. Now from the event, let's create a custom event trigger. Let's connect them with the flow. And now we want to trigger event from our win-loss panel. So let's select it first and let's copy the event name. And let's go back to our button when, and here, let's paste it to our event, three girls. Now we want from these trigger to run event, which is inside the panel below screed machine. So we need to drag and drop it to the target slot. Now we need to add our one argument. And for the winning, let's use a boldly throughout. So let's connect it and let's set it to true. Now let's select our flow and let's copy it. Let's select the button lose game object. And here let's also create new screen machine. And let's make it ambit as well as delete the events. It's press right mouse button and click on Paste. And because this is losing a button or change the bool value to false, now let's try it. So first save the scene and then press Play. Let's try click on our buttons and we can see they are working nicely. So let's turn off the play mode and we can finish here and let's continue in the next lesson. 19. Reusable Panel Animation And Export: Now we would like to add a simple animation to our panel. So when we trigger it, it will nicely show up. So first, we need to bring up the animation window. So let's move our mouse on the top of the script, the graph we know L is right-click on it. And here, let's click on, add it up, and let's click on animation. And now we can see the new animation we knows was created. Now to add the new animation, let's praise the Create button, and now we need to save it. So inside the Explorer we can see our assets folder. And here let's create a new folder called animations. Let's create the file with the name UI in, and let's press Save. And now we can see two things happened. First, we have a new component attached to our panel game object with the name and the mater, which is basically responsible for controlling this animation on the game object. And also we can see new button called out property. In our animation we know and there we can define what we want to animate. We would like to animate the scale of our window. So let's open direct transform, and let's click on a scale plus symbol. Now let's open it so we can animate the individual axis. Now when we click and drag our mouse over this timeline, we will see preview of our animation. So first, go back to frame 0 and let's change the scale for all the axes to 0 size. Now when we scrub the timeline, we can see our animation preview and it is working nicely. Now let's close our animation panel and let's test it. And we can see our panel is opening over and over. So to fix it, Let's go to our animation folder and let's select our UI in animation had here in the Inspector, we need to uncheck the loop time checkbox. So the animation will play only once. Now let's test it and we can see that window animation was played only rounds. Now when we are still in play mode, Let's try to disable and enable this panel. And we can see the animation is triggered every time the panel is a re-enabled. And later we will be using this behavior also in our games. But what I don't like is the animation speed and we need to bring back our animation window. Let's do it from the different menu. So first let's click on the window, then on the animation, and then again on the animation in our window appeared again. So let's dock it back where it was before. And to speed up our animation, we just need to change the samples value to 122. The animation will be playing two times faster. Now let's close the bundle again and let's test it. Let's disable and enable our panel again. And we can see our animation is much faster now, hand it looks much better. Now, our panel is almost ready matter we can adjust one more thing. And it is that we would like to see our pile always on top of any UI. Because when we are showing this panel, we already finished the game and we don't want from users to click on Other buttons and to make bile on top, Let's create new cameras component on it. Hell, I check override sorting and lead change order in layer 2, some big number, for example, 100. But now when we try our panel and when we click on the buttons, they are basically not working. So clearly we are missing. So let's click on our main canvas and we can see the scalar component we don't need in our panel. But it'll have also the graphic ray caster, which is basically responsible to handling the user inputs. And that is what we are missing. So we need to remember every time if we are adding your cameras component on any game object, which we want to be interacting with the user inputs like a mouse, we need to add also these components on it. So let's do it. And let's write graphic ray caster. And now when we are testing it, the buttons are working. Again. Also, don't forget to save the scene now to use our panel also in other projects, we need to export it somehow. And the easiest way is to create a prefab from it. So let's create a new folder called prefabs. Let's open it and let's drag and drop our parallel been lost inside. Now to export it, let's right-click on our brief up and let's click on Export Package and we want to export everything except the text Mesh bro folder. So let's uncheck did one. It will be always recreate it anyway, so we don't need it. Now press Export, hell, it's true some folder, but you will remember, Let's call it pile. We lose Empress safe in our package is nicely saved it there. And this is basically everything for this lesson. Thank you, and I'll see you in the next one. 20. Bridge Builder Overview: In this section, we will be creating bridge-building game from start to finish. We will start by creating grid pattern and with the shader graph, which we'll be using inside our UI image. Then we will be building our core breached creation state machine. So we will see every step of the bars creation visually. Also, we will be solving rotation and size of our rich bars. And we will be able to see where we want to place them. And then because we don't want to create infinite long bars, we will be clamping the maxlength of them. Then finally, because we want the physics simulation, we'll be creating joints between the breach bars, which we'll be holding our rich and we will be able to test it. And then we will add possibility to switch the bars between the concrete road or the wooden support. After their three, we'll create another material by which we will be able to see the load on our bridge. Then to slowly finish our game, we will be creating nice and environment and also the cheek and reach testers. And to make our game more interesting, we will be adding budget options. So we will have money limit to build our whole breach. So this was basically the overview of our game creation stages. I hope you will like this game and we can start. 21. Starting and Background Creation: So let's start and let's create new to the project. So if you have more versions, you can choose which one you want to use. We will be using these Varmus who click on debt, Qigong, the duty template. Choose the folder where your projects will be saved. Hamlet's define the project name. The project name will be bridge builder. Let's click on Create. Now let's way to beat. So the project we'll initialize. Now I will erase in the layout, so I will have the same setup is you. So let's start. Let's click on again view. The game will be an important trade mode. So we can change the resolution, so we will have the same result. And I want to use 800 by 600. And if you don't have it, Let's click on the plus symbol and let's add it there. So we will have the same settings. Now let's feed you make to the scene view. First, what do we want to do is to create some nice big round for our game. In the easiest way is created inside a UI canvas. So let's right-click on a scene, headlights click on the UI, and then on a canvas. Hannah, what we can see is the talus is a huge. Myself. I don't like to work with these huge canvases because they are in a screen space overlaid mode. So we can change it to the screen space camera. And here we need to pick our main camera. So let's drag and drop it D here. Now when we double-click on our camera, we will zoom in. Henry consider commas is already much smaller and I like it more. So we can set up cameras even more. So for example, when we had some UI elements, it will always be as similar as possible to the reference resolution. So inside a cow scalar, pled change the UI scale mode to scale with screen size. Hannah keep the reference resolution to be 800 by 600 and also change the value to be 0.5. Hindi settings are here for adjusting UI for different resolutions. So if you change your resolution of your game, the UI will still be as similar as possible to your reference resolution. Now inside Canvas, Let's create a UI image. Now let's make it stretchable. Now you want to use some big round for our image, but we don't hear any nice sprites. So let's import the assets from our project. Let's click on assets. Let's import the package. Helots. Find a one you've saved from our project files. Hey, let's click Import button. He now all the sprites are imported so we can use them. First. Let's rename our image to be BG as a background. The inlet selling the sprite palette, choose the sky one. Now you can see the sky is stretched by two. We can fix it quite easily. So let's click on our skies bright. Let's click on the sprite editor. Payloads move the green or lower age. We just basically defining the cutting of the sprite. And let's move it a little bit upper and don't forget to press Apply. And let's close the editor. And let's click back on our background. And here, pull it changed the image type to be sliced. And we can address little bit the pixel per unit multiplier, and we will be using 1.3. We can see the stretching is fixed. Now it looks much better and also the clouds are a little bit higher. So it will be more representing the sky in our game. And it's basically eat for these lessons are Thank you. In a CEO in an exile. 22. Grid Shader with Shader Graph: To continue, we will be creating a background image. We dust shader. We'll be representing the grid where we can place our breach connectors. And the easiest way how to build the shader is using shader graph, which is basically node-based shader editor. But for this one we need to import universal reign, their pipeline package. So let's do it. Click on a window, then click on Package Manager. They include corner Unity Registry. And here we need to scroll down and click on the universal render pipeline and click Install. Now let's wait until the installation will finish. And now when it's over, Let's close the package manager. Now to activate it, we need to create a rendering Gosset. So let's right-click on assets, layouts. Click on the Create. There are rendering and then on the universe around the pipeline and click on pipeline asset for viral render. And let's press Enter. And now we need to assign it. Like choose Edit Project Settings, click on a graphics highlights beak our Render Pipeline asset from here, I choose the one we already made, and that's basically it. I'll render pipeline is set up. Now we want to create agreed, so first select our canvas and let's create new UI image. And let's call it creation read. Let's make it against stretchable. And for this one, we need to create new material. So inside assets, let's create a new folder and let's call it Materials. And the inside, Let's create new shader. And it will be the universe, our Render Pipeline one. And here it will be the only trader graph. Let's call it Greek trader. And let's press Enter. Now to create material from me too, the easiest way is to right-click on the shader and let's create a material. Helots call it agreed to material. And as we can see, the failure is already assigned. Now let's open the shader. Now to maximize it, Let's click somewhere inside the shader graph editor and let's press Shift and space. First what we need to create a rectangle. So let's create new node Alice, right? The rectangle and click on it. And for changing wheat and height of it, Let's create a floor node. Now let's connect it to the width and height. It's working nicely, but we want to reverse the effect. So let's create a 1minus. Note how it's connected. Now the lower number is creating smaller age. So it is working hen to access these value from the material directly. Let's create a property from it. So one way is to create new flow. Note, let's connect it, and let's right-click on it. And let's convert it to property. Now the property in the canal called the Blackboard. But to change its settings, we need to go to the other panel called gravity inspector. Halide changed the name to be width and also changed a mold to be Slider. And minimum and maximum VL be between 01 and our default value will be 0.1. Now to create the rectangles over the whole image, we need to modify UVs of this rectangle. And the easiest way how to do it is to use position node hidden. By default, the node is working on vault space. And by the way, when we blinded to the ui's, we don't see more rectangles. We only see one wide spot. And it is because the UEs are expecting values between 0 and environment. And to modify our Lord position to her more values between 01, we can use in under an old, which is called fraction. So let's create it. And a fraction node is basically dividing the void space positions to the repeating value between 01. And that's why we can see more rectangles. And basically now it is working. Now to change color or the Alpha of our grid. We need to multiply the green to be the vertex color. So let's create vertex color node. Now we can connect it to our base color. So in our preview we can see the shader is working. But we also want from our grids to be transparent. So first, change our graphs and things to be transparent. Now we can use the Alpha input and now we can use also the split node. So we splitted the output from our Multiply node to the RGB and Alpha. And let's connect alpha to the alpha input. In a. Now we can see the blank lines. These are beard and they are transparent. But we wanted to one-way around. So let's fix it. Let's create one minus node. Enolates are reconnected. Now everything works so we can save it. Minimize the shader graph with the shift and space. Also, let's click on our scene view. And a now let's click on our creation greed. And also let's assign new material. And we can see the green is working nicely. But also we are getting error inside the console that our material doesn't have the main text property. So we need to fix it. So let's open the shader again. Hey, let's create new fixture duty property. And inside the graph in spectral it's changed a reference name to be underscore main thicks. And we will not use this property, but it needs to be there to error, to disappear. So it's basically necessary. So let's save it in. Now when we clean the console, the error will no longer appear. Now let's click again to our creation graph. And also let's click on the scene view. And here when we open our agreed trader, we can address the Wheat agreed. But let's keep the default value to be 0.1. Muddle it, click on the color and light chains that alpha value to be 30. So the Greeks will not be that prominent. An inside game view. It looks like a DCE. And then it's basically everything for his license or thank you. And I'll see you in the next one. 23. Bridge Connector Creation: Now let's continue how we will be creating connector point for our bridge. So let's open sprites folder and let's drag and drop connector to the hierarchy. And we want to add our first script on it. So let's add scrape machine component. Now let's create a new graph and inside Assets folder, Let's create a new folder and call it Scripts and insights. Let's create new one called Visual. Let's open it here. Let's call this graph connector. And we are doing it this way because sometimes you will be combining your project with C Sharp scripts. So for better organization, I'm doing it this way here. Let's save it. Now let's press edit graph. And if we are doing it first time in the project, it will take some time. So let's wait for visual scripting to initialize. Now when the graph window appeared, we need to dock it. So let's grab window handle L, It's dock it to the right. And also we need to expand it. Now let's maximize it by double-clicking inside the working era. Hell, it's deleted these two events because we will create different bands. Now what we want is to find a way how to place our connectors directly to grid intersections. And we want to do it inside editor because we will be creating our level and these will help us a lot. So we want first get position of our connector. So let's right-click on Workspace and a variety to get position. And we want to position from transform. Now we know our grid intersections are separated by exactly one unit. So to snap our position there, we need to always round our position 2 for lumber. And the easiest way is to use vector 3 int type. But right now this type is missing inside script explorer, so we need to add it. So let's minimize our graph and let's press Edit Project Settings. Now click on visual scripting. Let's open type options panel. It's click on the plus symbol. And we want to add type called Victor 3 int. And let's do it. Now we need to generate units. So we can see these type in our scripting graph. Now let's close the window. Now go back to our graph and let's search for vector three round. And we need exactly this node, which we'll round our position to whole integer number. And let's connect them together. Now we are getting the position, but we need to set it back to the transform. So let's create node called sit position. And again, we need the transform one. And we want to find some event which will be always working when we move our connector inside editor and we have one options. So let's create a new node. Let's go to events, then to the editor, and let's grab the drought gizmos event. And this event is specially made for showing is most, which are commonly wireframe shapes or icons visible inside editor only. But we will reuse it also for this purpose. Now, if we connect the even directly, it will be setting our position, even if we will know the move our connector. And to fix it, Let's create even hold. Now let's create new node called transform has changed, which is detecting the change in position or rotation or scale. That is, node must be always resurrected after it's detected a change. So we need to create new node called set changed. And we need the transform one. And let's plug it in the true branch. And we want to set it to offer value, which is already done. And to finish our graph, Let's connect the nodes together. Now let's test it. So let's grab connector and let's move it. And we can see the arrows are snapping to the grid. And when we release the mouse, also the connector will snap to the position. So this is good enough. Now the system, we need only four connectors which are defining our level. So we need to differentiate it somehow. So let's open our graph. Again. Let's create a new object variable called level connector. And the dye will be boolean, which will be represented as a checkbox. We can take are antiques for basically Boolean type is representing true or false value. Now let's duplicate our IV note by selecting it and pressing Control C and then Control V, L. It's a very connected to our system. Now let's grab our level connect or variable and connected to the if branch. Now, our system will work only if level connect or variable will be checked. Now to organize these graph, like to group it by holding Control and press and hold the left mouse button from the lowest left corner to the highest right corner. And let's call it snap level connectors in editor. And now we are done solid state steed. And now we can see it is not working. And the problem is the level connector value is unchecked. But where do we check it again? It is working again. Now to reuse our connector also in the runtime, we need to create prefab from it. So let's click on assets. And, uh, first let's minimize the icons. Now inside, Let's create a new folder and let's call it prefabs, handle it, open it. And now from here or here, Let's drag and drop our connector to that folder. Our brief up is selected. So let's change the default value of the level connector to be false. Because inside R Again, we will be creating these connectors dynamically. And they will be using the same prefab. And now when we click on a year he connector, the value also changed. But we need to override it easily in by clicking the checkbox. Now to build our tasting level, Let's duplicate our connector by pressing Control plus D. And let's move it to the right side. Now, if we check again our connector in a prefab, we can see the value is off by default. It is only overridden inside a connectors in the hierarchy. Now let's save the scene. And by this, we also finished this lesson. So let's see you in the next one. 24. Bridge Bars Creation: In this lesson, we will be creating breach bars, which will be representing concrete road or a wooden supports for our breach. And they will be always placed between the connectors. So let's open our sprites folder and let's drag and drop would embark to our hierarchy. Now we know data, we need to adjust the size of our bar dynamically. But when we are trying it by changing the scale, it will not look as good. So we need to find different way and there is better 1. First, let's change the drown mode for our sprite to be sliced. And let's try to change width. This doesn't work either, but the problem is that our sprite is not set up correctly. So let's change it. Select our voicebox pried open Sprite Editor. But we can see our sprite border is too big, so let's fix it. Let's close the editor and let's change the sprite mode to multiple. Open the Sprite Editor again. But first we need to click on apply settings. Now let's click on slicing and press slice. Now it looks like nothing happened. By the way anyway, click inside our wooden bar, the sprite edges are more tight. Now let's grab the green edges and let's define internal slicing for the sprite and be careful not to grab the actual spread border. And basically everything between these green lines will be dialed when we change the width. So let's find a nice spot where it will work. Now press Apply. Now let's select our wooden bar game object and we need to reassign our sprite because we were slicing it. So we need to read the wheat. And now when we change the width, it is working much better. So let's change the width to one. Let's open our prefabs folder and let's drag and drop our wooden bar game object there to create a prefab. Now, I know we will be creating the second bar with the same settings as our would-be her. So inside our sprites folder, we have also sprite representing the concrete road bar. And we will be using the same settings on it. So let's select it, changed the sprite mode to multiple inlets. Hope and Sprite editor press Apply settings. Now let's slice it again. And also lead change the left and right dialing edge and press Apply. Now let's click on our wooden bar game object. Changes prior to our concrete bar. Settings are working, so keep the size to one. And if the correct size was already saved in the main prefab, we just need to right-click on a width and click revert. And the main prefab settings will be loaded. And we can see we are not overriding anything. Now let's open the prefab folder and let's drag and drop it here. Now prefab creation panel appeared because we want to use and change settings only on one main prefab. We need to use prefab variant option which updated these will automatically end still it can have different options, likely friends, bright, and so on. So let's do it. Hey, let's call it concrete barbarian. Now we don't need our brief up in a scene. So let's delete it from here, our H0. And that's basically everything for this lesson. So thank you and I'll see you in the next one. 25. Bridge Creation State Machine: Now we will need to build system for our breach creation. So let's click on a creation grid, analytes at New Script machine on it. Now inside this machine, and we would like to use direct seen references. So we need to switch our graph to embed and we can delete, update event and water you'll be creating is the state machine inside our script machine. So let's create new unit and it is inside nesting, and let's click on state unit. Now I could also make the state machine as a separate component and it will be the same. But I want to show you also this option. Now let's connect it to the start event. So it will be starting with our game. Now let's select it and change the name to bar creation state machine. Let's open it. Plates maximize the window. Now we would like to create four states. First one will be called idle, and here we will be basically waiting for a mouse input to start breach creation. Now let's open it and it will not have any events solids ideally them. Now let's go bake while a well, hey, let's create a new script state. Now let's call it start creation. And these events will basically create two connectors and A-bar. And also it will update their positions so it's open it. And these ones will have only the enter state and update state. So let's delete the exit one. Let's go back. Now we need to create next state with the name finish creation, which will be basically finalizing the creation any to allow only been on interstate. Let's go back. And the last date we will be creating will be called cancel creation. And it will be responsible for counseling breach creation. If for example, we press right mouse button and insight. Hello, also only one enter state. Now we need to create transition between our states. So let's select our idle state and press right-click and click on Make Transition. Highlight select the Start creation state. Then from start creation and we want transition to finish creation. Now also we can create more bars advanced by left clicking over and over on our grid. So let's make transition from finished state back to the start creation. Also, when we are in starting creation state, we want a possibility to cancel it. So as make transition to cancel a creation, the last transition will be from Cancel state to idle state. So we can continue building our breach again. Now we want only our idle state to be turned on when the game starts. So let's click on the Start creation of state and press left-click, and let's select Toggle, start, hinder green indicator disappear, so the state is no longer automatically activated. So the only one which we want to be activated is our idle state. So these are state machine and this is everything for this lesson. So thank you and see you in the next one. 26. Creating Bridge Bars with Connectors: Now let's start working on our state machine. First, we need to define our transition from idol slate to creation state. So let's open our transition. And we want mouse-click event. So let's create new unit and from events, choose Guai in there. Let's select on a pointer click. Let's go back. And let's test it. Plates unzoom our graph and we can see all states in an RV see the idle state is blue, that means is currently activated, which is correct. And when we click, our state is changing to creation state, which is also correct. Now exit play mode. Halides maximize our graph. Again, Henry need to start working on the creation of state. So let's open it. First. When we enter the state, we want to get the mouse position and so we know where we clicked. So let's create a new node called good mouse position. Now the mouse position is in screen coordinates. We need to convert it to divert coordinates. So we need to create the new node called camera screen toward point. And let's pick the second one with one parameter. Let's connect them. And to get camera, Let's use any other unit called camera get made. And also connect these one. Now we have a board position of our mouse-click, and now we want to do the same thing as we did for our connector. We need to round this position to nearest whole number. So let's add vector three round to int unit. Hey, let's add them together. Now we need to adjust the zed value of our position because we want it to be always in 0. And the easiest way is to create a vector three, note, Henry want get x value from the vector solids out vector 3, I get x. And let's connect them together. And also we need y position, solids out, Vector3, get vine out. And also let's connect them together. Now let's keep the zed value to 0 and we have our screen to world conversion graph ready to save the subgraph for later use, we can create super unit from it. So let's select the connected nodes without the mouse position and press right-click and click on cut selection. And let's add a new unit. And inside nice thing, let's click on super unit. Hey, let's call it screen to world around it and press Enter, and let's click on Convert button so you can save it. And let's go to Scripts folder, then open Visual, and here let's name it screen to world, grounded and press Save. Let's open it. Let's paste our previous scatter graph. First, let's click on the input. And we need to create data input called position. And always remember when you're finished writing, don't forget to press Enter because if you don't do it and you will change the type, the name will disappear, and you will need to do it again. So let's define the type to be vector three highlights connected, read the screen to world point node. Now let's select output node and let's create a new data output called word position. And don't forget to press Enter. Type will be vector 3 as well. Now let's connect it to the graph. So now we will have screen position as input and we are getting word position as an output of our graph. Now let's go back to our creation state. Helots reconnected the mouse position with our super unit. Now, what we want is to instantiate two connectors in the world position. So first, let's add new unit called instantiate. And let's pick the game object van be the position rotation and also parent inputs. And we can connect our board position to position input. Now for the rotation, Let's create a quaternion good identity unit, which basically means no rotation. And let's connect them. Now we want to organize our instantiated connector and the parent game object. So let's create a new game object literal and connect it to the parent input. Now we need to feel the graph references be the actual objects. So let's minimize the graph. In first we need to feel the connector we want to instantiate. So let's drag the prefab and drop it to instantiate note. Now for our parent, we need to create your game object. And let's call it connectors parent. And let's drag and drop it into our game object node. Now we can maximize our graph again. Now when we instantiate our connector, we would like to store it into the variables part. We will need two of them. So let's create both and they will be object variable is two. Let's create first one and call it start connector. And also let's create a second man. Hey, let's call it N connector. Now we don't need to feel that types, they will be assigned automatically after we will be setting these variables. Now to say that the first one, let's drag and drop it to the work area. And a wild we are still dragging it. Let's press out and the name changes from get to the set. And now we can release the mouse button. We are getting the set variable node. And let's connect it with a instantiate outward. Now let's do the same of EDA second variable and also connected with the Instantiate node. And then our last thing, what is missing, is connected with their own enter state. So let's drag it to our first set variable and apparent data while it's connected to our second one. Now we can test it. Now let's click somewhere. And we can see under our connectors parent two connectors appeared. Here's they are aborted air. So these working. Now let's go back to creation graph. Let's open creation state. Now to make our creation process complete, we need to create also bar. So first let's split this event into more with a sequence note, and let's reconnect the first output. Hell, it's organized the first graph into group, and let's call it creates star and end Connectors. Now let's duplicate the Instantiate a node. Henry want also save the bar into the variable. So let's make a new object variable. Let's call it bar Henry. We'll set it with the instantiated node, can also be the sequence. Now instead of connector, you want to pick a bar, which we will be instantiating. So let's click on the target symbol and insight assets. We can pick the food bar prefab. Now, I see that we don't need to use instantiate node with the position and rotation because we don't want to specify position and rotation right now. The values will be basically default one, which means zeros, and we will be changing them later anyway. So let's create another instantiate naught and big the game object B, the original and parent input. Hell, it's big the wooden bar as we did before. Let's delete the old one. Panel is reconnected, the new one now for the parent, but it's minimized the graph. And let's create new empty GameObject and rename it to bar pair-end Hamlet's drag and drop it to our graph. And let's click on it and connect it to our parent. Now let's maximize our graph again, and let's organize it to a group. And let's call it created bar. Now let's test it. And we can see, we don't see the bar. But I see why it is because our bar parent didn't have reset, it transforms to 0 and it has some negative values on a z axes. So the bar is behind the big round in I reset it, we can see it correctly. Also we have the same problem on the connectors parent. But here we was lucky and it was working. So let's exit the play mode. Let's select the bar parent and also the connectors parent from the transform node opened the context menu and let's press reset. Now you can see zeros everywhere. Also, let check our prefabs. If we didn't create them, read some offsets. And we can see the connector have offset minus 4 in x-axis. So let's fix it to the 0. And others are good. Now we can try it and we can see we are creating two points n of Ambar. We just correct. And I think that's enough for this lesson. So let's continue in the next one. 27. Fixing Position, Rotation and Size: Now let's go back to our creation state k. Now we would like to update position of our second because first will be always on the place where we click matters. Second connector will be moving with our mouse. Now we can reuse our screen space to Workspace super unit B, the mass position. So let's copy it and paste it. And also let's get our hand connector variable and we would like to set position on it. Headlights connect them bought. And also connect the update event, which is setting these positions every frame when we are inside his creation state. Now let's try it. And we can see the endpoint is moving meet our mouse might of course, only to the nearest grid intersection because we are rounding the value. Now let's organize the nodes to the group and let's call it update endpoint position. Now we would like to update also the bar. So let's create a second has node L is reconnected. And award we want to connect to the second output is actually custom event trigger. This trigger, we will be updating our bar position and rotation on the bar itself. So let's create it. It is inside event, and here click on triggered custom event. And the event will be on our bar variable. So let's connect it. And even name will be updated bar. Now let's copy the name by selecting it and pressing the control plus C So we can use it later. Now not to forget how trigger, we'll have two arguments. So let's create them. And we will connect first argument to our start connector and the second argument to the end connector. And how we can organize it to the group. Let's call it update bar. Now let's go to our food bar prefab, hell, it's creating a script machine on it. Click on the new one. Let's save it to the script visual folder. And let's call it bar. First, let's delete these two events because we will be using the custom event. So let's create one plate space, the name update bar, and also lead change argument to two, which will be the first second connectors. And what we want to do first is to set our bar rotation. So let's create said rotation node and the transform one. Now you want from our bar to always be pointing to these two points. And to find the right rotation, we need to get direction between these two points and we can get direction from the positions. So let's add a new unit and let's create good position node. Hello. Let's duplicate it also for the end connector. And we will get the direction by subtracting these two vectors. So let's create subtract node. And we are subtracting and connector position from our start connector position. Now to get angle from this direction, Let's create angle. And because we are using 2D space, we can use vector to type pen to work correctly. We need to connect it to do input. And we want to calculate angle from the vector which is pointing always to the right. So let's create a vector to get the right note. And let's connect them. Now. We know the rotations are calculated in quaternions. So we need to create quaternions Euler node. And we was calculating only the zed value for the rotation and also connect the quaternion, said rotation. Now let's connect our event to the set rotation. And we can test it. And we can see the rotation is doing something, but it is not correct. And I know what is wrong. So let's fix it. Instead of angle note, we need to use sine angle node because sine one can go also to negative rotations. So let's created the vector 21 hand, let's replace it. Now let's try it. And now it is working correctly. Plates organize it to the group, and let's call it by rotation. Now let's continue. We will be fixing bar position. So let's maximize our bar graph. Let's take out the connector position from the group because we will be reusing data. Now we want to calculate the middle point between our connector positions. So r bar will be centered exactly between them. First, we need to create our denote enolates are the board positions together. Now to get the middle point, we need to divide this number by two because we have two connector points. So let's create divide node, and let's pick the one with the vector 3. Now let's zoom a bit so we can see the numbers inside divide note. And let's connect the additional output to the right slot a. Now to divide it, we just need to write to in all three axes. Now to set position, Let's create new set position node. And let's connect them together. Also, we need to connect it with our custom event trigger. So let's create sequence node lies reconnected. And let's connect the second flow output with our set position out. Here. Let's put the node to the group and let's call it bar position. Now we can test it. And we can see when we click and move our mouse around, the bar is always in the middle of our connectors. He's working nicely. Now you want to change bar size and we will be only changing the size in one axis because high to will be always same pen to get the actual rate, we just need to calculate the distance between these two connectors. So let's create new node called the stance heel, it's big the vector 3, 1. Let's connect our two points to it. Now for changing size, we need to use the sprite renderer, width and height value. So let's create new node, and it will be a sprite render set size. We want to change these values basically. Might we want to change only the y-value? So we need to get the old x value from the same node. So let's create sprite renderer, good size unit. Now we want only use y-axis from it. So let's add a vector to get a unit. Now let's connect them together. Now to block both values to set the size node, we need to create new vector. So let's write create vector to hell. It's connected both values to it. And also let's connect it to the set size note. And also in a sequence, let's add the third part and connect the flow with our set size node. And also, let's group the notes. Hell, it's called the group bar size. Now we can test it. And we can see it is working nicely. We only have a problem that the bar is rendered on top of our connectors. So to fix it, Let's select the connector brief up and lead change order in layer 2, 1. Let's test it again. And now we can see it is working nicely. And that's basically everything for this lesson. Select TO in an x-bar. 28. Multiple Bridge Bars at Once: Now let's finish our bar creation state machine. So let's select the creation greet game object. And let's open the bar creation state machine. And now we would like to finish our bar creation. So let's open the transition to the finished creation state. And we want to trigger it when we press mouse right-click button. So let's add your own pointer click event. And let's click and drag the output. Read half-life symbol n. Here, let's click on the pointer even data. Hamlet's find the button and out. Now the output of this node is being, that means the type is enumeration. And the name of this enum is input button of pointer even data. And we can use it to be the switch node. So let's create new switch on Inner node. And let's click on the arrow. And Alice ride the same name, input button on pointer, even data. And let's connect them together. And now they are working as a tandem. So depending which button I am clicking on the mouse, the specific flow will be 300. And here we want to connect left mouse button without trigger. And also don't forget to connect on point or click flow with the switch itself. And now let's go back and let's open the transition from finished state to the start creation state. And these will be custom event called go-to start creation. And we will be using event because inside the finished creation, we will do some calculations. But after dead, we want to change the state right away. So that's why we are using the event here. Now let's copy the name. Let's go back and let's open our finished creation state. Henle, it's odd or even through your retrievers making in the transition. And let's connect it. And also based the name go to Start creation. Now we can test it. First. Let's show our state machine. Let's press play. Let's click first-time somewhere. And now let's start clicking slowly inside. Agreed. And we can see that finish event is triggered and it is correctly going back to the start creation event. So we can make more than one bar. So this works great. Now let's maximize the state machine and let's add the option for canceling the creation. So first, go to this transition, and let's copy the pointer click logic. Let's go bake, helots, open the transition, and let's paste it here. And there. Now we want to connect the right button to cancel the creation. Now let's go back. Now let's open the council creation state. And here we want to destroy our connectors and var when we are pressing right mouse button. So let's grab all three of these variables. Hey, let's create this throwing out. And we need the game object van with a one parameter. Now let's connect star connector with a desk drawer node and also connect our Han enter state event on it. Now let's copy and paste the dice throwing out two more times. And let's connect them, have either end connector and also with the bar and Eddie end, just connect them together with a flow connection. Now let's test it. And when we are creating our bridge and we press right mouse button, the bar end points are destroyed. So these working correctly. But now when we try to click again, nothing happened. So let's fix it. Let's go back to the state machine and we need to finish our last transition, make to the idle state. So let's open it. And here we will be creating another custom event called go-to idle. Let's copy the name. Let's go back to the council creation node. And here the last thing in our flow we would like to connect is our event. So let's create a new custom event trigger. Let's connect it. And let's base there the name. Go to Idle. Now let's try it again. And when we create a bridge and then we cancel it, we can create it again and again. So everything is working. And basically that's everything also for this lesson. So thank you and I'll see you in an X1. 29. Reusing Bridge Connectors: Now we want to fix one issue. Let's create one bar. And also let's create second bar on a same place. And we have 1, 2, 3, 4 connectors plus 2 level connectors. So these wrong in our bridge is not reusing already placed connectors. So first let's select our connector prefab, and let's edit the graph and let's maximize it. And we want to store somehow already placed connectors. And the best way is to store it inside seen a variable. And also in a collection type called dictionary, we want to use cin variable because we can access it from any script machine on any object. And we want to use dictionary because we can store our connector here by a key. And the key will be the point position. So we can easily decide if the point is already placed in the same spot. So let's create a new scene variable. Let's call it point dictionary. And here we need to define the type and it will be the AOT dictionary. And I believe the ALT shortcut stands for ahead of time. And the advantage of this type of dictionary is that we don't need to define type of the key and also type of the values. And also we can combine multiple types together with this type of dictionary. So first, what we need to store in our dictionary are the level connectors and we want to do it when our game starts. So let's create start event. And we can find it inside events. And then lifecycle. And because we want to store only level connectors, let's copy our IV node together with level connector variable note highlights based hit higher. Now let's connect it with our start even. Now to add our level connector to dictionary, let's create new unit. Let's click on collection, then dictionaries, and then click on Add a dictionary item. Now we need to connect our dictionary variable headlights connected with our item. Note. Now, as I said before, for the key, we will be using connectors position. Let's create new unit called good position highlights connected PDA key input. Now for the value, we want to store the actual connector because the script machine is a component which is sitting on top of our connector prefab. We can just create these node. So we will get connector itself. Now calling the flow only for the true branch. So it will work only for level connectors. Now let's group the notes and let's call it add little connector to dictionary. Now we can test it. Let's press play. And to see our scene variable, we can use the game object, which was created automatically, and it has the same name. So let's select it. And we can see our two values are filled inside the dictionary. And we can see nicely the key are the positions and the values are the actual connectors. So these work correctly. Now to implement the actual reusing of the points, let's open our creation grid state machine. And let's open the finished creation state. First, let's split flow, read a sequence node. Now there will be three flows. And let's reconnect our event, trigger. Read the last flow because we want to do some other calculations before. Now for actual reusing of our connectors. Let's first get to the start one. And also let's get the position from it. Now we need to check if our dictionary already contains same connector in this position. So let's create dictionary contains key unit. Let's connect them together. And also don't forget to connect our dictionary. Now let's create IV note. Helots connect them together. So now we know if the point is already in a dictionary or not. And if it's there, we want to destroy our current start connector. Let's first create this through a game object node. Hell. It's connected them together. And also let's connect them with our first flow from sequence. Now, when we deleted are all connector, we need to set the value of the new one. So let's grab our start connector. And with pressed out, we will make the center node from it. And let's connect it with the flow. Now we want basically to set it with the already placed connector. We do still in a dictionary. So let's create a GET dictionary item note, first, let's connect our dictionary and let's connect the position. And also let's go into the set variable. Now you want to do it also for our n connector, Helen's do it by converting these nodes to the super unit. So let's select the nodes. Let's copy them. Now let's create super unit. Hell. Let's press Convert hell it, save it to Scripts folder, then visuals, and let's call it reuse point in the dictionary. Now let's open it and let's paste our nodes here. Now selling the input helots create new data input. Let's call it connector. Hell, it change the type to game object and let's reconnect it instead of r start connector. Now let's select the output node. Highlights are the data output with the name reused connector. And the type will be also GameObject. Hell, it is reconnected with a good item. Note. Now select out to note again here, let's create trigger output. Hell, let's call it out. And let's connect it with a day's throwing out. Now we can delete the old set variable. Now selling the input and also create van trigger input. And let's call it in. And let's connect it with an IV node. And also let's delete the other and get variable node. Now, we solve the possibility only for the case where we already have the point on the same place. Might've we need to solve it also for connector region is not yet in dictionary and we need to store it there. So let's create an item to dictionary note. If you can't select the right item, because it is flickering, you can try to use the keyboard arrows up or down and then press enter. Now let's connect it with the false branch. And the key will be the position, and the value will be our connector output. And also don't forget to connect actual dictionary variable. And also we need to connect flow with our output so it can trigger next flow even if we will be in the false branch. The last thing we need to fix is our reused connector input. Him for these, we can create celiac node. Hell. It's connected with the Contains key output. Helots are reconnected with a real ST connector input. And now we can decide what we will be outputting. And it will be depending if the connector is already in dictionary or not. And EVAs, let's connect the true value with a good item. So now it is the same how it was before. Hand for the files has used the connector output directly. Now let's go back. Now we can delete the middle nodes and let's plug our start connector and also the setter. Hell, Let's reconnect the flow also with our sequence. Here, we need to do the same for the end connector. So let's select and then copy and paste our nodes, connect them together. Headlights change the name V, the drop-down to the end connector. Now let's group the notes. Hell, it's called M reuse points in dictionary. Now we need to try it. First. Don't forget to save our scene. Let's press play. Hey, let's build the bars on the same level points. And let's cancel creation. And we can see we are reusing already placed binds. Now let's create lot of points. Here you can see we have still three Connectors, which is correct. But only thing which is not working is that we have a lot of bars and we should have only three. So we can fix this in the next lesson. So that's everything for now. Thank you and see you there. 30. Fixing Bars Overlapping: Now let's continue and we know we need to fix the problem with the multiple bars between two points. If we are creating them in the same place. To solve it, we need to store to the each point, the other point, which are connecting this point with a bar. And then we can decide if these two points are already connected. And AVS, we can ignore the another bar creation. Now let's select our connector prefab. And let's create an object variable called connected points. And the type will be a list of game objects. Now the variable also appear in a variable component. My leg check the prefabs which are already placed in a hierarchy. And we can see they are missing the new value we just created. And I'm not sure if this is a bug or if it should work like this. But we need to remember if we created new variables on our prefab. We need to update them manually on the brief apps which are already placed in a hierarchy. Now to update them, Let's select our first connector and inside variables component. Let's open the context menu and click on modified component and press revert. That means the component, we'll revert to all values which are defined in a main brief up. So now we can see our second variable appeared. But also we lost the check value for the level connector, so we need to check it back. Let's do the same for our second level of connector. Well it's a river, the settings and let check the level connector value. So now everything is prepared. Now let's go back to our creation grid, open state machine. Open the finished creation state. Let's maximize it. And what do we want to do when we are finishing our two connectors and bar creation. We want to check if these two points are already connected. Means we need to check their connected points variable we just created inside the each connector. And we want to check if the opposite connector is already in the list or not. So let's do it. Let's grab our start connector, get variable, and also n connector or get variable. Now we want to get the list of connected points. So let's create good object variable node, and let's connect it with our start connector. We forgot to copy the exact name of variable solids. Minimize the graph, selling the connector brief up, and let's copy the name connected binds. Let's go back to our state machine, open unfinished creation and its base, the name to denote. Now we know that the variable connector points is a list, and we need to check if this list contains the second connector. So let's create new node. And it is inside collections, lists. And let's grab contain item. And let's connect it with our connected points variable. Now we want to check if the list contains the second connector. So let's plug it here. And now we need if node. So we can decide what to do if the connector is inside lists or not. Now let's solve the case of n. The list doesn't contain this connector. And what we want is to add it to the list. So let's create lists at item node and connect the flow to be the false branch. Now let's connect the list itself and we want to add to the end connector to it. Now we are storing the end connector to the start connector list. And we need to do it also in opposite way. We need to store star connector in the end, connect earlier. And at the end, we will be asking if both of the lists already contained their opposites, connectors or not. So we will be creating end node where reveal plaque result from the first connector and later we'll apply the second one. And basically only then we can decide if the points was already connected or not. Now if we know, we will be doing it for the second. So let's make a soup or unit from this node. So let's grab the node. Let's copy them. And let's create a super unit. And let's click on Colbert helping. Let's save it inside our visual folder. And let's call it is point already connected with bar. Let's open it and let's paste the node. Select input. And let's create a data input and let's call it connector a. And the type will be game object. And also we need second data input, how its name it connect or B, and the type will be also a game object. Also, let's create trigger input, and let's call it inner. Now let's select output. Here. Let's create trigger output with the name out. And also we need to get a result if the point was already in the list. So let's create a data output and let's call it, is already connected. And the type will be Boolean. Now let's connect, connect or a really good variable. So we can get the connected point list, then connect second to the contains item node. So we can check if the point is already in a list and also do it with add item to this node. Now we can delete our old nodes. Also, let's connect flow with the event node. And now let's connect that contains item to our output. And also we need the Connect flow first from true branch and also from end of our false branch. Now, even if this looks correct, there is a slight problem. Later when we will be using is already connected output. The result could be wrong. And the reason is because we will be asking it later in the flow and the initial float will evaluate the graph correctly. But when we will be using output later, this flow will be evaluated. And if the result was false, now the result will be true because at the end we are adding that connector to the list. So to overcome this issue, we can use Sketch note, which will store the result for the first evaluation. And the result of this cache will not change during re-evaluation. So let's create a cash-out. Let's connect what we want to cache. And we want to cache contains item result, and also connect the cache results to each branch and also to our output. Now to store cash, we need to reconnect it with the input node and also reconnect the flow from the cache to the AV node. Now let's go back. Let's delete the old nodes. Let's connect star connector to connect our a and N connector to connect our b. And also let's connect the flow from the sequence note. Now we need to do it also one way around. So let's duplicate the super unit. Let's connect it to the flow, and let's connect the connectors in the opposite way. And now we can use our EndNote. So let's connect them with a boat result. And also let's create each node. And let's connect them together. And now you can decide if the boat connectors already contained the opposite connector. So the bar is already created between them. So we can delete our new bar, which is basically inside the bar variable. So let's get it. So let's create destroy unit, the van with a game object and a one parameter, hell, it's plugged in together. So connect the flow from the true branch and also fix the flow here. Now let's group the notes. Hell, it's called them, check if bar already exists. And here create another group and let's call it delete already existing bar. Now we can test it. Let's create bar on the same place, over and over. And when we cancel the creation, we have only two level points and only one bar. So these works correctly. Now let's try new bars. And after we cancel creation, we have three bars and together three connectors we disconnect. In by this. We are also ending this lesson. Thank you, and I'll see you in the next one. 31. Clamping Max Length: Now we will be adding new options to our bars, which will be limiting their maximum length. So it will no longer be possible to connect our level connectors. We just one-bar. First, let's select our wooden bar. Helots are the new object variable and let's call it maxlength. Hello change type two integer. And now for our wooden bar, Let's set it to four. And for our concrete barrier, let's set it to three. Now let's go to our creation grid. Let's open the script machine. Hell, it's open Start creation state. And under our update event, we would like to restrict our position to maximum length. So inside sequence note, let's add new flow connector. And let's a reflow did with the second one. And in the middle, we will be calculating our maximum length. And for restricting our length, we need a direction of r bar. And we can get it by subtracting the end point from the start point. So first let's get our start connector variable and let's get position from it. Now let's create, subtract, note the vector 3, 1. And let's connect them together. Now the subtraction real give us direction and also length. And we want to restrict the length to the maxlength. So let's create a new node called vector three clump magnitude, where magnitude basically mean length of the vector. Let's connect them. And now we need our max length variable and we can get it from our bar. So let's get the bar variable first. And let's create new getObject variable node. And let's connect them. Now I forget the exact variable name. So let's copy the variable name from our wooden bar. It is a maxlength. Now let's face it back to our OR gate variable node. And let's use it as our length limiter inside our claim node. Now, we have a vector with direction and clamped length. But by subtracting the two positions, we lost the information about starting point of this vector. And right now it would be in a 00 000 hen. When we think about it, we just want this vector to start from our star connector position. And we can move this vector simply just by adding another vector to it. So let's create new other note. Here, let's add to our clamped vector, Start, connect or position. And now let's use it inside our set position node. Let's make more space inside the group. Now let's test it here. Now when we are start building our breach, the length is limited. But now the endpoint is not always snapping to the grid intersection because the values are not around it. So let's fix it. And we can fix it by rounding this vector, the lowest full number. Because if we want to have maximum length and if you would rounding it normally, sometimes it will be rounded to the higher number. So the length would be bigger than the maximum one. Hand. To rounding it to the lowest full number, we can create a node called the vector 3, hint floor to int. And a floor means that we want to get near as smaller number hand, for example, if we would like to have highest whole number, we need to use Cl2, int and coelom. It's shortcut for ceiling. Now let's reconnect them also. We said transform. And now we can try it. And now we can see the bar is limited. And also it is always snapping to the grid intersections, so everything is correct. Now the last thing, let's group the nodes and let's call it changing bar length. And also I just realized it. We don't need how are three flows from our sequence? So let's fix it back to the tool. Let's reconnect it. Hell, it's disconnecting the red van with the right mouse click. And basically this is everything for this lesson. So thank you and I'll see you in the next one. 32. Creating Physics Joints: Now we would like to start working with the physics simulation of our breach. Now to use our bridge with a 2D simulation system, every breach prefab and it's their component called Rigid Body 2D. And the rigid body is responsible for simulating physical behavior of gravity. It is used also with the colliders. It can simulate realistic interactions between objects where they're hitting each other and bouncing around. So first, let's click on the Connect or prefab. Halides out a Rigid Body 2D component. Now, when we tested, the simulation kicks in and our level of connectors are falling down. But our level of connector needs to be always studied. Math still interact with a physics correctly, so we need to fix it inside a graph. So let's select our connector prefab and let's open the state machine. What we want is to change our rigid body 2D type to be static. So let's create a new node and let's write SET body type. And let's pick the note and we can connect it directly be the end of our first flow, because the flow is only evaluated when the game starts, and also only on our level connectors. And it's what we want. Let's change the body type to study. So our level connectors will never move, but they are still included in a physics simulation. Now where do we test it? We can see our connectors are staying and we can select one of them. And we can see its body type is static, which is correct. So the connector physic is set up and, and now we need to set up the bars. So first, let's select our would embark prefab helots click on Open prefab button. So now we have more space. And let's also other Rigid Body 2D component. Then let's add a box collider 2D. And the collider is basically representing the bar shape physics world. Right now, don't worry the size of the collider is bigger, but we will be changing into, in our script graph. Now because we are building bridge, you would like to connect our bar with a star and, and connector. And inside physics, we are connecting two objects with the joints. And here we need special type of joints called the hinge joint 2D. For example, it's the similar connection which is holding the doors. We did our frame and we need to create two of them, one for the start connector and a van for the end connector. Now on both the joints, we need to uncheck the auto configure connected anchor. Because we will be connecting anchors inside graph. And it's good to do some issues in a simulation later. And also one of the problems we will be solving is to figure out how to move this joint to the start and the end of our bar. Because the values are not in the word position, but in the local space of this object. But first, let's solve the collider size. Let's go to our graph. And we need to add a new node called box collider 2D set size. Let's connect it to the flow. Header size will be the same as inside our sprite render, so we can connect them together. Now we can test it. Let's save the prefab and let's exit the prefab without clicking on the arrow has run again. And we can see everything is falling, which is basically correct. So let's do it one more time and let's pause the execution with this button. Now let's double-click on our wooden bar, and we can see slightly the green edge around our wooden bar and the size is same, which is correct. Now let's open the wooden bar prefab again. Now let's maximize the graph. Now we need to set up our joint positions. So to get our two joints inside this graph, we need to bring them here as a variables. And it is because inside the prefabs, we should not use embedded graphs. We should always use the saved graphs which are stored on the disk. And it's why we can't use direct seen references, but it is no problem to use variables. So let's create first one, let's call it star joined. And also let's create a second one, and this one will be enjoined. Now let's change type the both of them to the hinge joint to D. Be careful not to select the hinge joint readout today and they'd advance is for the 3D physics. Now let's minimize the window and we need to feel them from inspector. So let's drag and drop first joint component to the star joint value. And also let's drag and drop the second one to the n joint value. Now let's watch it again. When we are moving, are joined with the anchor value. We are moving them in a local space. And the local space means like we are moving the joint relative to our bar center, which in local space is always in 000 000. We will be solving this problem from our creation state machine. So let's save the prefab and let's click on Exit. Let's select our creation greed. And let's open our state machine, and let's open our finished creation of state. Now to say this Angkor, we want to do it only if the bar is created. So we can use the false branch from our IV node where we know the bar is created and we are not deleting it. First, let's create a sequence and it's connected with the false branch. Now, first what we want is to change position of our joint anchors and we can use the set anchor node. So let's pick the hinge joint 2D one. Now set Angkor, need our actual joint which is sitting in the bar itself. So let's get bar variable. Now, our bar has a joint inside object variables. So let's create the get object variable node. Let's connect them. Now I forgot the exact name of our first joint, so let's check it inside our wooden bar. And let's copy the name of star joint. Let's go back. And now I see I made a mistake. I connected them to the wrong slot. So let's fix it. It's based the name star joint air. So now we are getting start joint from our bar and we want to connect it to the set encore input. Now we want did Angkor will be on the position of our star connector. So let's bring star connector to our graph. And we want to get position from it. Now as we know, our connector positions are in world space by the Angkor are in local space. So to convert the position of our star joint to bar low-cost space, we can use node called inverse transform point and we want the position one. And let's connect start connector position to the position slot. And because we want the result in a bar local space, we need to connect our bar to denote transform slot. And now we can finally connect them with our set anchor node. Now we also need to connect our joint to the extra start connector rigid body. So let's create a set connector body. Hamlet choose the hinge joint to the one. Hey, let's connect our joint to first input, and let's connect our start connector to the second input. Now we know that start connector is that game object and set connected by the needs rigid body type. But if our star connector have this component already, we just drew the set connected Valley note. We'll get it the rigid body automatically. Sometimes this conversion works in visual scripting and sometimes not. But here we are good. Now let's use our sequence first slot to connect the flow and also connect our set and core. Now let's clean it a little bit, and let's put the node to the group and let's call it Start joint setup. We need to do the same for our enjoined solid. Select the whole group. Let's copy it. And let's paste it here. Also, let's rename it to end joint setup. Let's connect the flow from the sequence. Now let's change the name for the start connector and we can use the drop-down because he was using this variable already. So let's click on n connector name for the star joined variable. We don't have the end joint here. Hand to be safe. Let's find the name in a wooden bar prefab. And let's copy it. Now let's go back. Hello, it's pasted here. Now this should work so we can try it. And don't forget to save the scene. And we can see, we can't test it properly because the physics is running from the beginning of our game in everything is falling, but we will fix it in the next lesson and it's basically everything. So thank you and see you there. 33. Testing Physics: Now to test our physics properly, firstly, we would like to create a game manager. So let's select a sample scene and let's create empty game object, and let's call it managers. And inside, Let's create and run Hamlet's call it game integer. Let's create screed machine component on it. And let's change it to ambit. Now we don't need the update event, but we want to use the start. Now to turn off the physics. We can do it easily by changing the timescale value. And because the physics works with the time value, if we change it to 0, the physics calculation will basically stop. Let's do it. Let's create a new node called setTime scale. Hell, it's connected to the start event and a 0 value is what do we want? Now to run the physics again, we will need to change the timescale value back to one. But we want to do it from the custom here. And so let's create customed, even note, hell, it's call it start physics. Now let's duplicate our set timescale note headlights reconnected with our custom event handler, change a value back to one. Now to test our game easily, we can create a UI button folded. So inside our cinemas, let's create an empty game object. Hello, Let's call it game UI. And we want to add component from the layout, and it will be the horizontal layout group. We will be organizing our buttons horizontally. Now inside, Let's create UI button text Mesh broad, and this window will appear and to use tags mesh Pro, which is better replacement for the older units it takes component, we need to import the essential files. So let's click Import. Now we can see our first button. And now let's change the button color to green. And also let's add outline component on it. So the button and we'll have a nice outline effect. And let's say that the effect distance to five and minus five and also change the outline color to white. Now let's rename the button to button starts. Now we need second button. So let's duplicate this one and let's call it button. And now click back on our game. You, I LL Jake control child size, width, and height. So both of the buttons will be squeezed inside the game UI raked, which size is 100 by 100, but we will change it. First. Let's more direct to the right screen corner. So open the encore preset by clicking on the symbol and then braced together shift hosts of EDA out. And now let's click on the corner symbol and our rate will be snapped to the corner of our screen. Now let's change the position to minus 30 on eggs and also minus 30 on y. Let's also change the width to 260, unhide, 245 pellets out at little spacing between our two buttons. So let's put 15. Now let's select the button Start takes game object, changed, that takes value to start. Also, let's turn on how to size. How it changed maximum number to 72 texts will be automatically resized. Many of you will be changing its area. And when we zoom to our button, we can adjust our texts border. We did these white markers. Now let's change the color of the takes to be white. And also we can tweak the font material little bit solids at outline and set it to 0.3. And also we can inflate our font v, The dilate value. So let's use the zero-point three as well. Now to copy the settings also to the other button, we can do it easily. It's click on the context menu on our text Mesh PRO component helots click on the Copy Component. Now let's select the text on the End button. Helots bays the component values there. Now let's change the text to restart. Let's tweak the size little bit. Also let select the button, LLC change the color to red and also to be correct, let's rename the button to restart. Now the buttons are prepared. Now inside manager parent, let's create a new empty GameObject. Hell, it's call it UI Manager. And it will be responsible for giving functionality to our UI buttons. And also let's add screed machine component or it can change it to embed. Now we can delete both events and let's create new one, which is called ONE button click event. It is basically inside events and inside GUI. Now let's connect it with our button by dragging and dropping it here. And when we click on the button, we want to restart our game. And easiest way how to restart the game is to reload the scene. And we can do it with a new node called Scene Manager logged seen, hell, it's big the van with a senior name parameter. Now let's save the scene and the name of the scene is a sample scene, which is not great. So let's open our scene folder where the scene is saved. Let's rename it to bridge builder. Now let's press Enter and this window will show up immediately. And it is basically Unity realized that we had opened a scene, but we changed the name. So it wants to reload it. So let's do it. Now let's go back to our UI Manager. Helots copy the name of our scene, and let's paste it inside a scene, a name Import. Now let's implement the second button. Let's duplicate on button click event. Hello. Let's drag and drop the second button on it. And we want to use our custom trigger. We just changing the timescale and starting the physics. So let's add new, trigger our custom event note, and let's connect them together. And we want to use event. We just sitting on the game manager. So first we need to feel the game manager inside our custom event trigger input. And also we need to define the event an aim. So let's copy it. Hell, it's based in there. Now let's save the scene and let's try it. Let's build some breach. Alice, press Start. And I see I made a mistake because the game just restarted and I think I missed that the buttons. So let's go back. Hell, it switched the buttons. Now let's test it again. Let's build a bridge. Let's press start and we can see the physics is working and our breach is nicely hanging. Let's press Restart and the game is restarted. So this is working also correctly. And it's basically everything for this lesson. So thank you and I'll see you in the next one. 34. Changing Bar Types: In this lesson, we will be creating UI buttons for creation options. So we can choose, if you would like to build our bridge reader would bar or with a concrete bars. So inside Canvas, Let's create empty game object, and let's call it creation options. It's moving to the right corner of our screen. Let's change the position to 30 in x and minus 30 in my hand away it will be 100 and a height will be 45. Whole. So let's create a horizontal layout group component on it. While it's also check control child size, width, and height. Now let's create button inside. We can also delete the text because we don't need it. And for the image, let's pick our food bar. But the lead change image type two simple and also sprite looks squeezed solid check preserve aspect, and now it looks correctly. Now let's rotated little bit by 45 degrees, also lead change button transition to none. So the button will not have any effect when we click on it. But to visually see if the button is clicked or not, we will add outline component on it and lead change FFD stance 23 and minus three. Let's change color to green. And also let's get rid of transparency. Now let's rename the button and let's call it buttonwood has duplicated and the second one will be Button wrote. Hello, change image to the concrete bar and also lead change image type two, simple, and that's it. Now we will add functionality to these buttons inside your eye manager. So let's open it. Let's create another onclick button event. And let's duplicate it. And let's fill them with our buttons. Now, what we want first is to enable a green outline only if the button is clicked. Now, our outlines are enabled by default, so we need to disable them in one way. How to do it is to store them into the list. And then we can loop over this list and decide which outline will be turning on or off. So for these, we need the actual references for our button game objects. So let's drag our first button directly to the graph, highlights select it. And also let's do the same for the button road. Now let's put them to the list. So let's create a list node. Let's plug them both to the 0 and to the slot. And then available, you'll be clicking on the buttons. We will trigger our custom event. We didn't number parameter. And by this parameter we will be deciding which index from this list we can use for the updating outlines. So let's create a custom event note with one parameter. Hello, Let's call it change bar. Now let's create for each loop note. So we will be processing all values from these lists advance and also willing to connect our list to it. And also let's connect it with a custom event. And now we need to compare if currently protest item index in foreach loop is equal to number from the custom event. So let's create equal note. Hey, let's connect it with an index output and also with the event argument. Now to turn on or off our outlines, we need to create a node called outline set Enabled. And we can connect the equals output directly to the owner of parameter. Because if we click on a bar, that even argument will be 0 and also the index will be 0. So the equal result will be true and it will set outline on. And then the loop will process the second button and the index is 1 and that equals the result will be false. So the outline will be turned off. If we want to do it for each item in the loop, we need to connect the flow from the body output. And also we need to connect actual buttons with our outline note, Henry can do it from item output from the loop. Let's connect them. Now let's group denote and let's call it change click the button outline. Now we need to call this custom event from each button. So let's create our custom event. And we want to use one parameter which will be defining to be 0 or one. And let's copy and paste the name change bar event. And to do it all advance, we can use select on flow node. Let's connect button would to the slope a and also button or 0 to the slot B. And now we need to black to the CELAC. Note that differ and values. And the values will be selected automatically depending which button we are clicking. And we need numbers 0 and number 1 and 4 date, let's create a node called integer literal. And the first one will be 0. And let's connect it to the slot a hand, let's copy and paste second one and change it to 1 and plugging two slot B. And now we can connect it to our custom event trigger. Now we can test it. First. We can see both of our buttons. I have outlines which we will fix later, but let's select the button and now the other button gets unselected hand it is working also for the second button. So it is good. Now to select one bar when we start the game, Let's make start event. And let's connect it with the first slot. And it means when the game will start, the boot button will be pressed selected. Now let's try it. And we can see the Borlaug's nicely. But if we are creating our breach, we are always using our food bar. We need to fix also this. And for that, we will be creating one more event. So let's copy and paste these one. And it will have also one parameter and the name will be set bar to instantiate. Let's connect it. Now let's connect also the select Output. Do it hand is event will be defined inside our creation grid. So let's drag and drop creation greed game object on the event object variable. Now let's open our creation grid. Let's create new custom event. And let's copy the name from our UI Manager. And it is the sidebar to instantiate. And let's paste it back. And also changed the event to have one argument. Now we need to create a variable. We will be storing reach bar prefab we would like to instantiate. So inside object variable, Let's create new one and let's call it bar to instantiate. So let's grab it. And with the outbreak. And we will be setting it from the two prefabs. It will be devoted bar prefab and also concrete bar prefab. So let's drag and drop them to the graph. Now we need to use select note, but we need to use the select on integer one, because now we don't have multiple flows, we just have one argument which can be numbered 01. Now let's click on the node and we need to add here these two options. The first is 0 and the second is one. Now let's connect them together. Also with our center. And also let's connect the flow. Now, we have to store the correct brief up for our creation. And now we need to use this variable somewhere and we will use it inside our state machine. And basically we need to use it instead of this selected prefab. So let's bring bar to instantiate variable, and let's connect it with our instantiate a node. Now we can test it. Let's save the scene, and let's press Play. Now by default, the UD m bar is pre-selected and this is working. Now let's change it. And we can see we are using concrete bar, but also we are getting some error in the console. And I guess I know what is the problem? Basically the variables in our concrete prefab, Marianne are not updated. This is the similar problem as we have with a brief app's already placed in a scene. So let's fix it. Let's select our concrete bar prefab. Here. Let's revert the variables component here. Now we are getting older missing object variables. My lead change bake the max length 2, 3. Now they both have the same variables. So let's try it again. And this time it is working without problems. And that's basically everything also for this lesson. So thank you, and I'll see you in the next one. 35. Show Bridge Load Shader: Now we would like from our reach to be breakable. So let's select our food bar and concrete bar prefabs. And I change the brake force for both of their joints to 300. And now let's build the bridge. Press start and we can see the breach is breaking nicely. But we would like to see visually how big load is currently on each bar and we can do it with the material. So inside materials folder, let's create new shader. And it will be only trade a graph. Let's call it show a lot. Now let's select it and let's right-click on it. And let's create material. Let's call it show logged material. And we can see it is already filled with our show called shader. Now let's open our new shader. Plates, press Shift and space to maximize the view. Now first we want to see the texture of the sprite. So let's create a property and it will be texture to the one. Let's press Enter and let's change the reference name to underscore main text. And we need to do it these exiled way. Because if we are using underscore main text property, if we plug this shader to the sprite render, it will automatically use the sprite assigned in the sprite render, and then we can modify it from here, how we want. So let's grab it to our work area, end to use it. We need to create sample texture to denote. And we need to connect them together. And I want to blend our texture with some color by our load. And for these, we can use the letter per node, which stands for linear interpolation. First, we need to connect it with some color we want to blend. So let's create color note. Hello, change that color to red. Hell, it's connected to slot B and two slot a. Let's connect our sample texture to denote RGB value. Now to blend it with a load, we need to create new float property and let's rename it to load helots connected with the t input of the lab node. And now we want to connect the result of our layer per node to the base color. Now, our sprite is using also transparency, so we need to change the settings of the shader. So let's select the graph settings and let's change surveys value to transparent. Now we can save it. Let's press Shift and space to minimize the window. Now let's go to our scene view. Now we want to add a shader to our brief up. So let's select Prefabs folder. Let select food bar and concrete by our prefabs. And let's change the material to the new shoal of material. Now let's select our wooden bar prefab. And let's open our graph. Here. We want first calculate the load on our bar. And the load we will be calculating from our two joints. And because we will be reusing the values, but only in this graph, we will create them has our graph variables. So let's create the first graph variable called Start hold. Handed type will be float, and this one will be for our start joined. Now let's create a second one with the name and load, and it will be also the flow type. And this one we'll hold value for load for our n joint. Now let's grew up start load and you want to set it. So let's grab it and let's press out. Now we want to calculate load from our star joint. So let's get to the star joint variable. Now to get the exact load on our joint, we can use get the reaction force. So let's create it and we wonder hinge joint to the 1, but we want to calculate it relative to our brake force. So basically we will see if joint is going to break. And for this, we need the hinge joint 2D get brake force. Note. Now we need to divide these two values by the reaction force is a vector. So to get a float value from it, we need to use getMagnitude note. Let's connect them. Now let's create divide node. So the result will be number always between 01. And that's what we need because inside shader, the layer node is expecting only the values between 01. And now we can connect it also with our set Start Load variable. Now the problem could rise when the joint actually breaks and we will get an error. Because if the joint breaks, that joint component will be destroyed automatically and this graph will not work. And to solve it. We can create, now check node and let's connect it with our star joint. And now we can decide that we want to process this graph only if the joint exist. So only from the note now branch. And also because we don't know when this joint breaks, we need to check it all the time. So let's create update event and we can restrict it little bit with the IV note my asking if we are simulating our game or in other words, if the timescale is set to one. So let's connect them. Let's get timescale note here. Let's create also flowed literal. Let's create equals node to compare them. Hey, let's connect them to our even out. Now we are asking if the physics is on. So let's change the float to one and EVAs, let's update this graph, but we will be doing more calculations. So let's create a sequence node and let's connect it through deadlock. Now we want the same calculations also for our enjoined. So let's select the graph and let's copy and paste it here. Let's connect it to the second sequence node, and let's change the value to n joint. And also let's use our end load. Now let's group all the nodes. Let's call them update load. Now we want to show this load inside our material. So let's create a third sequence output. But inside material we only need one value. And here we have two values, start and end load. So we need basically to combine them somehow. So let's get started load variable and also get any load variable. And what we want, we want to see maximum value from these two. If the van load value is one and the second is 0, we always want to get one hand to do it. We can create node which is called maximum. Hey, let's connect it. Now. If we want to pass the value to material, we need to do it inside property block. So let's find set property block. And it is the vine of EDA sprite render with properties. And we want to use set flawed property. But right now the properties are not in visual scripting by default, so we need to add m. Similarly, how we was adding the vector int type. So let's do it. Let's go to Edit Project Settings and inside the visual scripting, let's open type options. And let's add a new type. And let's add material property block. And let's regenerate units so we can see them inside our graph. Let's go back and we want to set fraud property. So let's write set float. Hell, it shows the material property 1. Now let's connect the float value. The name will be reference name of the Lord property inside our shader. So to get it, let's open our shader graph again. And we can see the name is load. So let's copy it. And let's paste it back to the name input. Now to use it, we first need the old material property block. So let's write good property block. Let's pick this pride or render. And we want to create new one from it. So let's find create material property block halides, use the first one. Now let's connect the properties with all the notes. And also let's reconnect the flow and also connect it with our sequence. And this is basically set up how we are changing the property of our shader from visual scripting. Now let's group the notes and let's call it show load. Now we can test it. Hi, it's build a bridge and let's press start. And we can nicely see conveying the bars are completely read. The joint will be broken. Handy's is also everything for this lesson. So thank you, and I'll see you in the next round. 36. Creating Game Environment: Now let's create some environment for our game. In here he view, Let's create a new empty game object and let's call it environment. Inside, Let's create new 2D game object. And it will be the sprite shape. And let's pick the closed shape. Now the shape is just white, but we can make it much nicer. But for that, we need to download some sample assets directly from Unity. So let's open our Package Manager. Lets open to these spread shape and let's open samples. And let's import the first one. Now we can click on our spreadsheet profile and we can pick one of the downloaded samples, highlights big the grass anaerobe profile, and this one will look as good in our game. Now let's change the shape. So let's click on Edit Spline button. Now let's select all corners advance and we want them to be sharp. So let's click on this sharp corner icon in the target mode option. Now let's grab one corner and let's move the shape little bit to unselect all corners. Let's click somewhere outside. And now we want to adjust corners one-by-one to look similar like this. But let's try to keep this straight line the same height as our first breach connector. Let's rename the shape to Cliff. Now we would like to add the shape to our physics calculations because later we will be using some pasting objects which will taste how breach. And they will be working on top of this cliff so they needs to interact with it. How do we know that this object is always studied? It will not fall down. So to include it to the physics calculations, we don't need to add a Rigid Body 2D component, we just need some collider. So let's add H collider 2D component. Now to update it, let's move the slider and we can see the collider is fitting the shape of our cliff. And I change the offset to 0. And now inside edge collider settings increase the age radius to 0.5. And now our collider is fitting the shape nicely and we have also nice rounded corners. Now let's duplicate our cliff. Here. Let's edit the spline. Select all the corners, and let's grab one corner and move them all to the right side. Also keep it the same height is our breached connector and we can address the little bit more. And I also don't like the shape of the first one. So let's address also dead one. Now I like it more. Now to test our breach, we can create some breach tester object, which will be trying the strength of our bridge. So let's click on sprites folder and let's drag and drop. She can spread to the hierarchy. And let's put it under some parent. So let's right-click on it and let's create empty parent. And our chicken is the child of this parent. And let's rename parent to be testers. Now let's move our cheek and somewhere above our cliff. And to add chicken to our physics calculations also, let's add collider, and it will be circle collider 2D. So you want the streak and to be affected by gravity, so it can fall plates up Rigid Body 2D component as well. Now you can see the collider is much bigger than our chicken shape. So let's adjust did change the radius to zero-point 35. Now to test our breach correctly, we would like from our chicken to move from left to right. And because we are using physics simulation, we can add constant force to the component on it, how it changed the direction in x axis to be one. So this force will be pushing these chicken or from the left to the right. Now we can test it. First. Let's build some bridge. And let's press Start. Now we can see the bridge is shaking and it looks somehow unstable in our chicken is heating the wooden support and it is not able to go on concrete road of our breach. Now the problem is that all of physics objects are interacting together and some of their colliders are overlapping. And the physics wants to fix this by trying to pull them apart. So that's why the breach was shaking. The other problem was that the chicken is heating wooden bars, but we would like to ignore them. We won't need to just go through the road. So for these type of problems, there is easy fix. We can assign our physics game objects to different layers. And then inside settings we can define reach layers should interact together and region out. Now to define our layers, let's select some game object and click on the default layer. And let's add a new one. And we will be adding four layers. First will be Road, second will be Support. Third will be environment. And last van, we'll be tasters. Now we need to assign them to our game objects. So let's select our chicken. Click on the default layer and let's assign it to tasters layer instead. Now let's select both our cliff. Let's assign them environmental layer. Now let's go to our prefabs folder and let's select our voodoo bar, and let's assign it to the supports layer. And finally, let's select our concrete bar and let's assign it to the road layer. And now we need to set up the layers interactions for the physics system. So let's open project settings highlights. Click on physics 2D, and we need to change these collision matrix first, let's uncheck all interactions completely. Now we would like to have collisions between tasters and testers layers. So for example, if we add more chickens, they will interact together. Then we won't interactions between tasters and environment. So the chicken can walk on top of our cliff. Then we want interactions between testers road so they can walk or the road. And that's basically everything what we need. So let's close the window. Let's save the scene. Now let's test it. First. Let's create a road. Then the wooden support. And we can see that she can, can go through the bridge, which is great. So physics is working how it should. Now the only problem is that the game is quite easy, so we need to make it a little harder. Let's select our chicken and let's increase the mass to ten. So the chicken will be 10 times area. Let's right now. Now we can see that the chicken is heavier by the force which is pushing it from the left to right is too weak. So let's fix that. Let's select our chicken and let's change the value of our force from one to two. Let's try it again. Now we can see it is working better. And also the game is harder because this type of rich should not all that much. Now, I realized our bars and chicken are rendered behind our environment. So to make it nicer, we can fix it. First, let's select our mood bar and our concrete bar. Change order in layer 2, 1. Now let's select our connector and change the order to two. And also let's select our chicken and change it to one as well. Now let's test it one more time. Now it is much better. And now the bars are rendered in front of our cliff. And that's basically everything for this lesson. Thank you, and I'll see you in the next one. 37. Bridge Budget Options: Now we want to create budget options for our game. So our breach creation will be limited. So we will need to build our breach only with some money. We currently have now firms we would like to have some visual indication for our budget. First, let's select our cameras and inside, Let's create a new slider. And let's call it the slider budget. Firstly, it's more, it's B-mode to upper age, change the position in x to minus 30, y two minus 20 and width will be 220, and height will be 65. Now we don't need the slider handle, so we can delete it. Now let's select our field aria, and let's switch to direct tool highlights a resize our raked to the edges of our slider. Now let's open the fill area and inside feel gameObject like change width to 0. Now let's try our slider. So let's select our slider parent and let's try to change value. And we can see the slider is working nicely. And let's keep the value for now to 0.5 so we can see the big round and the slider advance. Now let's select our field again. Hello, change the fill color to green. Now let's select the background. Hell, It's an outline component on it. How it changed the effect distance to five and minus five. And also let's change color to white and also increase the alpha value for transparency. Now to see also how much money we still have in our budget inside our big round, let's create new text. And it will be the text Mesh pro, one hand, let's call it budget texts. And we can see the budget is behind our field area and it is because the rendering order is respecting the year our H0. So if something is lower in here, here it is showing on top. And to fix it, we need to add to our text new component called cameras and VDS component, we can override the render sorting, select Shake, overwrite sorting, healthy change the order in layer 2, 1. And, and now that text is nicely on top of our slider. And now we need to fix the alignment. And also put here some text, something like star symbol 1000 and dollar sign. And I'm using the star symbol because when we'll be changing the stakes inside our graph, I want to clearly see if that takes the most change properly. And if he has, it will appear without the star. It's also stretch the text rec to transform to be as big as our bigger on pair-end and also lead change that text material. But right now, if I change some value in the material, our start and restart taste, which we are using in the buttons, will be changed as well. So basically, if we want to change these texts material independently, we need to create new material. Press it. Let's go to material section. Let's click on context menu and let's click on Create Material, press it. Now it is independent material so we can change it first. Let's turn off the outline. Whole slowly changed the vertex color to almost black one, but not so much. And also in material, lead change to dilate value to something smaller like zero-point two, and also adjust these yellow border lines. But it takes size doesn't change. So we need to enable auto size and how it is adjusted. And let's think a little bit more. And now the budget slider is ready. Update these budget. We need to do some visual coding. Now first let's open our game manager. And here we need to create to object variables. One will be level budget, and the type will be integer. And we can set it, for example, to $100. And these value will be the budget for our whole breach. The second variable we need to create is current budget, and the type will be also integer. Now when our gain start, we need to create a custom event trigger. It will be updating initial values to our UI slider inside our game. It will have our two variables as arguments, and the name will be updated budget UI. Now for the first argument, Let's grab our level budget variable and to feel and the second argument, we need to first initiate our current budget variable. So when our game starts, the value will be same as our level budget. So let's grab the current budget and let's press out so we can set it. And let's set it with our level budget. As I said, now let's do it only when our game starts. So let's connect the start even with a setter. And also let's connect the flow without trigger event. And also let's coning the arguments where first will be our current budget and the second will be the level one. Now let's copy the name update budget UI with control plus C. Now let's open our UI Manager where we will create the actual custom event for our budget slides or update. Let's paste the name headlights, change the arguments to 2. Now let's open our game as a graph and we need to assign the correct game object where our custom event is solid. Drag and drop the UI Manager here. Now let's go back to your manager. Now first, what we want is to set text for our slider. We know that takes, is take smash bro, but we don't have it inside our search panel, so we need to add it there. So let's go to Project Settings. Click on visual scripting. And now I know that we will not find it inside the type options, but we can add it inside the node library. And let's click on the plus symbol and let's add a new assembly. Alice takes mesh bro, and, um, the first one. Now let's originary at unit. Now we want to set our tech mesh protects. So let's write Uruguay set text and it will be the tangled mesh Pro you go, I said tags without any parameter. And firms legs grew up that takes from our slider and let's put it inside our note. We can connect it with our flow from the event. Now our actual budget number is a floating point number, but we would like to show only four numbers in our budget slider. So we need to round our actual budget to integer. And for this, Let's create map. If I round to the node. And let's connect it with the extra budget, which is the first argument. Now to add the dollar sign directly after the number, we can create string format note here, let's pick the first one. Let's connect our rounded number 2 argument. Now we need to create curly brackets. And inside Let's write 0, which will represent our argument. And after the brackets lays variety dollar sign. And in the result, we will not see any brackets with a 0 by they will be replaced with a rounded number and a dollar sign. And the dollar sign will be at the end of it. Now let's reconnect it. Now let's try it. And we can see the number doesn't have the star symbol in front. That means it was replaced with R Script and it is working exactly how we wanted. Now to update also the slider, Let's create sequence. Let's reconnect it. Now let's group our notes and let's call it updates lighter text. Now do change slider. We need to create new node called slider set value. The slider is expecting the value always between 01. Now to convert our actual budget and current budget to value between 01, we can simply divide them. So let's create the right note handler first will be current budget, and the second will be a level budget. And let's connect it with our set slider. Now let's minimize the window and we need to feel the slider from our hierarchy. So let's grab slider budget and let's drop it to our node. Denotes and let's call it set slider value. Now let's connect the flow and how we can test it. And we can see it is working because slider is full now. Now to calculate the cost of each bar, let's first select our wooden bar. Let's open the script. Now we need to create a new object variable, and let's call it cost per unit. And the type will be integer. And this variable will define how much we will be paying for one unit length of our wooden bar. Then we need second variable called actual cost, and it will be also integer. And this one will be storing the real cost of our current bar, because it will be multiplying the cost per unit length of r bar. So we will get the real number, how much the whole bar costs now for the bar. And let's say that the cost per unit to 30. And for our concrete bar, we need to first update the variables with a revered. And let's set bake the maxlength with three, and let's change the cost per unit to 40. Now we need to calculate the actual cost, which we will be subtracting from our budget. So let's open our bar graph. And here, after recreating the size, we can calculate the actual cost. So let's grab our actual cost for setting it. Let's get value from our cost per unit and we want to multiply it with our size. And we can grab the extra size from the distance directly. And let's set the result to our actual cost. It's also connected flow here, let's group the notes and call them, calculate actual cost. Now we need to solve and morphing. Imagine that we are building our breach and we will build it over budget right now. Nothing happens to mean to erase trick the building process. It, we don't have enough money. And for these, let's open our creation grid and insight state machine. Let's open that transition between a star creation and finished Creation. And here we can restrict if the current bar can be builded or in other words, if it can go to the finished state. So let's create even a lot. And let's reconnect it with the true branch. Now we need the current budget variable. So first let's create a gate object variable node. Now let's minimize the graph because the variable is sitting on our game manager, so we need to grab it and drop it into our graph. Now let's open our game manager and let's copy the name, current budget. And let's go back to our transition. Let's use this name. Now let's get our current bar variable. And we want to get actual coast from it. So let's create another GET object variable node. Let's get the name right. And it is the actual cost. So let's copy it and let's go back here. Let's paste it here. Now we need to ask if our current budget is greater or equals to the actual cost. So let's create greater or equal note. Let's connect current budget to the first slot and the actual budget to the second and also reconnect them with even out. And if our current budget is more than our actual cost, we can create the bar. Now what we are missing is the way how to update our current budget. So let's fix it now. Let's go back one level and let's open the finished creation state. And now if we are creating the actual bar, we need to update the budget. So let's add one more flow to the sequence. And we will be triggering event inside our game manager, which will be responsible for updating our budget. So let's create new triggered customer, even note. Hello, Let's call it update current budget. Hamlet's connected with a sequence flow. Now we know this event will be defined inside our game manager, and let's drag and drop our game manager on it. And we will be passing here the actual cost of the bar. So let's get our bar variable. Let's create a good object variable node. And it's calling them together. And we need to find the correct name again. So let's select wooden bar. Now let's copy the actual cost again. And let's go back and paste it here. Now we need to define this event inside our game manager. So first let's select the name and let's copy it. Let's select our game manager has opened the graph. And here we need to create custom event space, the name. And also let's add man argument for the actual cost of the newly created bar. Now we will be modifying our current budget. So let's bring it for setting. Now we can connect the flow and the new value which we want to set to our current budget, we will get by subtracting our actual costs from it. So let's create, subtract. Note. It's also bringing the current budget has a good variable. Hell, it's connected to slot a hen. We want to subtract from it. Our actual costs are grand, and let's update the new value from the result. Now when we call this update current budget event, the budget gets updated, but our UI slider will be still same. So let's copy the update budget UI event, and let's connect these one. And LIGO's current budget as first parameter and a level budget will be the second. Now let's group the notes and let's call it update current budget. Now let's test it. And we can see something is wrong because our chicken is falling immediately. And I think I know why. Let's go back to our game manager. In here. I accidentally disconnected the flow for the setting the timescale to 0 and to start, so to fix it, Let's create sequence note. And let's reconnect them both. Now let's test it again. Let's build a bridge and we can see the budget is updating nicely. Here when we are on $10, we can't build anymore. So this is working also correctly and is basically everything for this lesson. So thank you, and I'll see you in the next one. 38. Budget Slider Colors: Now we can modify our slider to lose much nicer, because now we have only one color and it would be nicer. That is, color will be changing to orange when the budget will be passing the middle point, and also the red when it will be near the end. So let's open our UI Manager. Now to change colors, let's use the node called image setColor. Analytes, your select on flow. Note here, let's connect them together. Henry want to use three colors. Now let's create color literal. Note headlights duplicate it two more times. For us will be green. Second we'll be orange, and the last will be red. Now let's connect them. Now we know that the middle point of the slider is value 0.5. So we need to compare our current value if it's more or equals to it. So let's create the greater or equals. Note, let's change the B input to 0.5, and let's connect it with the output value. Now we need to plug it to the AV node. Also, let's reconnect the flow. And we are asking if our current slider value is greater or equals to 0.5. Let's connect it to be the input a, which represent the green color pen here I've made a mistake. Let's plug it here. Now let's duplicate the greater or equal note, and let's change the value to 0.25. And laser ray connected with our slider value as well as duplicate evening with one more. And the first connect the flow from the false branch. And let's connect them with a second, greater or equal note, he now we are in a branch. A slider value is less than 0.5 and we are asking if we are at least greater than 0, 25, and EBS, let's pluck through branch to the input B and finally, false branch to the input c. Now we forgot to set our image game object inside a setColor node. So let's do it now and let's grab the Field game object and let's drag it to the set CAR node. We will be setting the color basically on this image component. Now let's group the notes and let's call them set slider color. Let's save the scene and we can test it. Let's build some bars. And we can see when we pass middle point, the color changes to orange, her later to read. So these working, how it should hand these is basically everything for this lesson. Thank you. And Assyrian and excellent. 39. Adding Win Loose Panel: Now we need to create win and lose condition. So if we fall down, we will lose the game and it will cross the bridge who you'll read. And also we want some paneled to appear, which will show us if we win our hose. And luckily in the beginning of our course, we made our win-loss parallel so we can import it to the project. So let's click on assets in per package, custom package highlights find our panel win-loss package. Now let's import everything. Now the panel appear in the prefabs. So let's drag and drop it to our Canvas. And we want to remove it from our prefab. Because if it would be still pref up, we will get some errors because we are using the embedded graph on it. So let's right-click on it, and let's click on prefab hand. Let's click on unpack completely. And now we don't need a prefab anymore, so let's delete it. Now. Our panel will be disabled by default. So let's rename it and let's write disabled at the end. So we can clearly see when we opened this project that is parallel should stay disabled and it is not disabled by mistake. And also let's don't forget to disable it by unchecking these trig box. Now, our panel has already the events setup in before and we will be using them also here. And to use it, we will need to create a winning and losing conditions for our game. So first, let's select our managers parent, and let's create new empty GameObject highlights, call it when hellos manager, and let's create empty game object under it, and let's call it when trigger. Now let's duplicate it, highlights call a second one and call it loss trigger. How to detect if we cross the bridge, we can use another physics component which is called 300. And it is basically normal 2D collider. We did three or settings turned on and Eve are JICA, we'll touch this collider. Basically nothing will happen visually. But our three-year collider wheel around event called On Trigger Enter. And this is what we can use to detect if we win. So let's select our reentry your game object. Let's add a box collider 2D component, halides, move it on other side of the bridge. And don't forget to check the East Trigger checkbox. Now select our loss trigger game object and we can do the similar thing. We will create long three or collider under our bridge. And if the cheek and we'll fall down, it will run the trigger as well, and these will be the losing event. So let's add a box collider 2D as well. Jake is trigger. Let's move it under our bridge and let's make it longer. On the excise, we can use the number 20 and I'll select the both triggers and we need to change their layers because not all layers are included in a physics. And we also know that only tester layers are interacting with each others. So let's assign them these testers layer. Now let's select our win-loss manager parent. Let's add a new script machine on it. And let's change it to embed. Let's delete both events. Here. Let's grab our winter eager to the graph. And also the lowest trigger. Now let's create on three or enter to the event. Hell, it's connected with the first game object here. Let's duplicate it, and let's connect also the second one. Now in both cases, we want to open our win-loss panel and we know it is disabled. So first we need to enable it. So let's create a new node called Game Object Set active. And we want to activate our win-loss panel. So drag and drop it onto these note when we need to turn it on by checking this value. After these, we would like to call the events which are sitting on this panel. So let's create custom event trigger. Henry need to assign the same of in-law spiral inside the hand. But now I realize we need more assignment of the same game object. So we can grab this game object directly to the graph. Hell is reconnect both of the nodes with this game object, and now it's much more organized. Now let's find the name of the event we want to run inside our panel, and it is the start name event. So let's copy the name. Please go back. It's based it to the event. We want to pass through or ES argument to our starting event to define if we are winning or losing. And we can do it with a select on a flow note. Now let's connect our events to it. Now when we will be running our wind trigger and we want to pass through value. So let's create Boolean literal, hell, it's connected to the a slot and don't forget to check it. So it will be true. And let's duplicate it. Let's uncheck the value, and let's connect it with the slot B. Now calling the float with a set acting note. Here, let's connect select with our argument. It should be it. So let's try it. First. Let's save the scene. And now press Play. Now let's start again. And if our character will fall, the loose panel should be triggered. And we can see this working Handel played again. Let's press yes. Now let's try to build the bridge which can hold our chicken. Let's start it. Henry can see the wind panel appear as well. So this game is basically finished. Now if we would like to play it directly inside Windows, you can click on file and build settings and press belt. Now it will ask you where to save this game and when you choose the folder, you will click on Select Folder. And the building process should start. And after it hold the important files of the game will be stored in that folder. And there will be also the exit file which will be running this game. And this is basically everything for this game. I hope you like building it. So thank you and I'll see you again.