
For example: 7 / 2 gives us 3 lots of two with one left over (3 * 2 + 1 = 7). The % operator in C# performs a division on two integers (whole numbers) and then returns the remainder. This does so by making sneaky use of some math theory, which I will go into very briefly here. The first line determines the current frame. The logic for each cursor is the same, all that is changing is the array of images being referenced. If there is only one image we do not need to handle an animation. Each branch of the if statement is handling a different cursor which has more than one image for it. Now to evaluate that method and see what it is actually doing.
#Cursor screen wrap unity skin
(Note: I have only recently fixed this, so the skin on github is not correct until Part 17) Now create a reference to yet another GUISkin at the top of HUD.cs This will make sure that our cursor image is drawn as large as possible. The one setting we want to change is to set the Border, Margin, and Padding for a Label to be 0. First, create a new skin inside your skins folder (in the HUD folder) called MouseCursorSkin.
#Cursor screen wrap unity update
We then update any animation our cursor might have to make sure we have the correct frame set for our cursor, find out where it needs to be drawn on screen, and then draw it there using a Label.Īs usual, there are some steps we need to take in order to make this method work. To make sure that things always behave we will define a skin for our cursor (a new default skin will do fine) and define the group drawing area to be the entire screen. If not we need to cancel the system cursor and draw our own in its place.

If the mouse is over the HUD area of the screen we will use the system mouse cursor (although we could easily change this at a later date if we wanted to). Rect cursorPosition = GetCursorDrawPosition() GUI.BeginGroup(new Rect(0,0,Screen.width,Screen.height)) Add the following variables to the top of HUD.cs Now that we have some images to work with, we need a way to be able to access these within our HUD. Each of these needs to be saved into the appropriate folder.
#Cursor screen wrap unity free
Here are the cursors I am using for this project, feel free to use them if you wish. Many of these actions will not be added until later, but it is still useful to have the cursors there. As you can see, we are going to have a number of different states that we will display to the user with our cursor.

Inside the new Cursors folder create folders with the following names: Attack, Harvest, Move, Pan, Select. We may as well put all of our cursors into folders now, so that when we want to use them we can just grab the ones we want.

Inside the HUD folder create a new folder called Cursors. This form of isolation and independence is a good thing.īefore we begin drawing we should create a place to store all of the different cursors that we are going to use. This also means that changing state does not need to worry about any of the draw code. Drawing a cursor will be based on that state. As part of this we will introduce the concept of cursor state. The first thing we want to be able to do is to draw a custom cursor. Building a real-time strategy game in Unity 4.1 using C# scripting
