Unity: Ruby's Adventure
Today we learnt how to use unity and started to follow this tutorial: Ruby's Adventure: 2D Beginner - Unity Learn.
This is a screenshot of my outcome from this lesson. |
We first looked at how we could access unity from home, by using a free personal license.
We also looked at examples of unity games and websites like learn.unity which are helpful.
To start the project we opened unity and created an empty project. I then experimented with moving the mouse around in the 3D space, which was similar to other 3D softwares. (Middle mouse for hand tool and right mouse for eye tool to look around)
For unity it is important to keep in mind the the version you are using, those with the same year should be compatiable but others not as much.
We clicked the '2D' button at the top of the scene to change to 2D, we also moved the 'game' view (What the player will see) to the right of the 'Scene' view so we could see both at once.
Next we added in a sprite by saving an image of the 'Ruby' Character and then importing the image and changing the texture type to 'Sprite' (Remembering to click apply to save changes) We could then drag the sprite into the scene.
By clicking on the sprite in the heirarchy you can see the properties of the sprite, like trasform which is where the sprite is. The shortcuts for the move tools are Q,W,E,R and T. It is important that the camera is around z=-10 (if the sprite is at the origin 0,0) So that the camera can 'see' the sprite. We also changed the 'Camera Projection' to orthographic so that the view is 2D. The camera size is how many units to the left and right that the camera sees.
We then added a Rigid Body 2D and Polygon Collide 2D to Ruby and added some ground pieces with Box Collider 2D so that when we click play Ruby will fall (Due to the rigid body) and collide with the ground. In the play mode you can move things about however the edits will not be saved.
We then added our first script, unity uses C# Language so we added a C# script (Assets>Create>Folder ("Scripts"), Assets>Create>C#Script or right click in the folder and click Create>C#Script.)
When the script is first opened there is some code already in it, it is important not to delete any of this.
The start function includes code which unity executes only when the game starts, while the update function executes every frame.
We added some code to the update function:
Vector 2 position = transform.position;
position.x = position.x = 0.1f;
transform.position = position;
This would move the sprite 0.1 units to the right per frame (after adfding the script to the sprite and pressing play).
The f after 0.1 is to signify a floating point/ number with decimal points.
To make the sprite move when you press left/right arrow you would need to check the input manager (Edit>ProjectSettings>InputManager) and find the horizontal input. Here you would find that left = negative button and right = positive button. Therefore you can use this to create the script.
One of the lines in the second iteration of the script is 'Debug.Log(horizontal);' this would print the horizontal value in the console everytime it changes, alternatively you could use ("Horizontal value is : " + horizontal) which would print 'Horizontal value is : 1' for example.
Once we had made the script so that the sprite goes up and down we then went on to design the map for the sprite using Tile maps. In order to do this we needed the Tilemap packages (Window>PackageManager>Packages:UnityRegistry "2DTilemapEditor"). We then added a Tile map (Hierarchy window, right click>2D object>Tilemap:Rectangular), then we added a tile palette (Window>2DTilepalette) created a new palette and dragged the Tile.png into the tile palette and named it "First Tile"(We also added a folder for "Tiles"). We could then click on the tile in the palette and paint it on the grid with the brush. However, there were gaps between the tiles and they were not connected so we had to edit the pixels per unit within the Tile.png to 64 (The size of the image) then click apply.
After this we used some Tile set images, which are images which contain 9 tiles. We changed these into tiles by selecting the tile, changing the sprite mode to multiple and ppu to 64, then clicking apply. We then sliced the tile using the sprite editor (Which requires the 2D sprite packages) and slicing it with grid by cell count (3 by 3). After clicking slice and apply we could then drag the tile set into the palette.
We also created an additional tile map for vegetation and changed the order in layer so that it was infront of the environment tile map.
We could then design the background/environment. Overall I am happy with how mine turned out, but I think I could have experimented more with it.
Need to look at Beginner Scripting - Unity Learn. And a useful website for tile maps: Opengameart.org
Comments
Post a Comment