Wednesday, February 8, 2017

Day 5

Today I will be hopefully finishing my game that I started.

I started off by making a cube, naming it "Pickup" and resetting its x,y,z coordinates to (0,0,0).

Then I raised its Y-axis by 0.5 so that it sits on top of the plane and scaled it to 0.5 so it looks a bit smaller. Then I tilted to angle of the to 45 degrees in all angles.

But this still wasn't enought

I had to make it catch the players eye when looking at it. So I decided to add a spin to it (like a literal spinning cube).

So I made a new script and called it rotater and started coding in it. 

The code was easy to do. This is it:


And this made it spin

:D

After I found out about something called a "prefab" which is pretty much like a blueprint for the object and store all its information and child objects in one file. So to make a prefab you drag the object to the project tab and it automatically makes a prefab. I then got the cube and started duplicating it with CTRL + D and placing it around the plane 12 times like the numbers on a clock. Then using the prefab I made, I can change all a the cube's properties at once by using prefabs. So I colored all the cubes yellow to make them stand out.


And now what I needed to do is make them disappear on contact with the player. 

So I coded it by making a "trigger" that activates when you touch it. And activated some things in the cube's box collider component.
This was my code:


So now it picks them up when I touch it.


Now I had to add a counter that counts how many I have collected and show it at the top of the screen.
So I made a new text object and it automatically puts it in this thing called a 'canvas' which is pretty much what it's called. You can move things like text and images inside the canvas and it moves it automatically on the game screen. So I renamed the text to "Count Text" and made it in the upper left corner of the screen

.
Now i had to go and script. I made a variable called count and made it equal 0. And now i set it that when you collide with the cube "count = count + 1" (adds one to count). Then I made a whole new function, called it SetCountText() and defined it with what the text will say "countText.text = "Count: " + count.ToString();".

Then I called this function inside the trigger function. This is the code.


And now it counts the points :D


Now the last thing I had to do was a text that popped up when you collect all the pickups. So I made a new text, called it "Win Text", placed it a bit above center, and made an if statement in the code that made it show up when you collect all the pickup objects.


Now the game is finished! :D

Tomorrow I might start a new tutorial.

No comments:

Post a Comment