From the course: Unity 5: 2D Movement in an RPG Game
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Map position utility - Unity Tutorial
From the course: Unity 5: 2D Movement in an RPG Game
Map position utility
- [Voiceover] Now, before we start putting the player in the correct position on the map, we're gonna need a better way to calculate those positions. One way to do this is by creating a position utility that will allow us to reuse the same calculations throughout the project. Let's go into our scripts folder, right click, and create a new C# Script. We'll call this PosUtil. Then, let's open it up in MonoDevelop. This class isn't going to extend MonoBehaviour, so let's go ahead and remove that as well as the start and update methods. We're going to create a new public static method with a return type of void called CalculateIndex. Here, we're gonna take an int x, an int y position, and convert it into an index ID. In order to do this, we're gonna need an int that represents the width of the tile map and we're gonna use a key word called out that allows us to pass in an int that'll represent the index value. Out is useful when you want to pass in a value and change that value as a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.