Later on this tutorial, we are going to add the rest of its behavior.įor now, the PlayerUnit will have only the Sprite Renderer and a script called UnitStats, which will store the stats of each unit, such as: health, mana, attack, magic attack, defense and speed. So, first let’s create a PlayerUnit prefab with only a few things for now. (scene.name = "Battle") Īlso, the PlayerParty will have two children to represent the player units. SceneManager.sceneLoaded -= OnSceneLoaded Private void OnSceneLoaded (Scene scene, LoadSceneMode mode) SceneManager.sceneLoaded += OnSceneLoaded Otherwise, it should be set as active if the current scene is the Battle scene. If so, the PlayerParty object must be destroyed, to avoid duplicates. The configured callback (OnSceneLoaded) checks if the current loaded scene is the Title scene. It also adds a callback when a new scene is loaded and set the object as inactive, so that it won’t be shown in the title screen. This script keeps the object from being destroyed when changing scenes in the Start method. In order to keep the PlayerParty alive when changing scenes, we are going to use the following script, called StartBattle. In order to do so, we are going to create a PlayerParty persistent object, which won’t be destroyed when changing scenes. You will also need to properly set its position so that it will be created in the correct position in Battle Scene. In our game, we want to keep the player units data saved even when changing scenes. Public void loadNextScene (string sceneName) Then, we set the OnClick callback of the play button to call the loadNextScene method with “Town” as parameter.
This script will simply define a method to start a new scene given its name. The PlayButton object will have the following ChangeScene script for the OnClick callback. On the other hand, for the Button object we need to set its OnClick callback. For the Text object we only need to set its message. The first one is a Text, while the second one is a Button. We are going to create another layer called HUD, and put the HUDCanvas on this layer.įinally, we need to create the two HUD objects. However, in order to show this canvas over the background one, we need to properly set its sorting layer. Let’s start by creating another Canvas following the same process as the BackgroundCanvas. In the Title Scene, those elements will be a title text, and a play button. Now, we need another Canvas to show the HUD elements. The source image will be the background image, and we can set its native size in order to properly show it. Also, the UI Scale Mode (in Canvas Scaler) will be set to follow the screen size, with a reference resolution of 1280×960.Īfter doing that, we create a new Image object as a child of this canvas. In order to do so, we need to specify the camera of the canvas, which will be our main camera. Title Scene Background canvasįirst of all, we are going to create a Canvas to show the background image in the Title Scene. You can do that by creating a new Canvas called BackgroundCanvas, and setting its render mode as Screen Space – Camera. So, you can use them in your games, even commercial ones. All sprites are available under the Creative Commons Zero (CC0) license. The sprites used in this tutorial are from the Superpowers Asset Packs by Pixel-boy.
We hope that you decide to take the course and join the thousands of students who have already taken their next steps in advancing their Unity game development skills using a sophisticated, intermediate project based course.You can download the tutorial source code files here.
We even provide another Unity project to demonstrate AStar pathfinding! So while it took the creator of Stardew Valley over 4 years to create his game, you can get a head start by using this course, potentially saving many months or even years of development time ! This is one of the most comprehensive intermediate Unity 2D development courses on Udemy. This course is massive with over 44 hours of lecture videos, 99 lectures, a starter assets pack, and a complete Unity project that you can download to follow along. We’ll start with a blank project and then develop the game lecture by lecture, covering all the code and Unity configuration you will need.
We’ll explain how to develop many of the core systems and game functionality. Have you ever wanted to create your own Farming RPG? Games like Stardew Valley and Harvest Moon have been incredibly successful, and you too can develop your own game with the help of this course.