Friday, April 28, 2017

Monthly Post #3 - April in Review

What I Learned This Month
-How to add a delay into a C# script

-How to make a raycast with a limited length

-How to add a pause mechanic

-How to add a ui that appears when a button is pressed

-How to add a slider that controls an integer value

What I Accomplished
This month I continued making my audio-only game. I've added a main menu, a pause menu that appears when "escape" is pressed, a raycast that will be used for the combat mechanics, and added a delay that simulates drawing a sword.

Next month, I will start adding enemies. The pathfinding won't need to be very complicated; they just have to move towards the player, then deal damage per second to the player when it touches.






















Thursday, April 27, 2017

Day 40: Audio-only Game: Day 15

So, I finally figured out how to add the WaitForSeconds delay into the script. I first made a new void function:

I then added "StartCoroutine", and gave the coroutine a name: "Wait".


Finally, I added an IEnumerator with the "Wait" coroutine name. Inside that, I added "yield return WaitForSeconds(3);", and then a line afterwards that changes the CanAttack boolean to true.

I then simply added a line that calls the WaitToAttack function whenever the "1" or "2" key is pressed, effectively adding a delay that simulates drawing a sword, orpulling out a bow.















Tuesday, April 25, 2017

Day 39: Audio-only Game: Day 14

Are. You. Kidding me? So much for getting an answer! On to the audio!

Anyways, I first need some sound effects. I found a sfx pack on the unity asset store, and some other sound effects on a sound effects website:

http://www.sounddogs.com/previews/101/mp3/129686_SOUNDDOGS__bo.mp3

http://www.sounddogs.com/previews/2742/mp3/456574_SOUNDDOGS__bo.mp3

http://www.sounddogs.com/previews/101/mp3/129696_SOUNDDOGS__cr.mp3

Unfortunately I couldn't find any guides for audio that make sense, but I did get some more script added to the game. I added a delay between switching weapons and being able to attack, using a boolean called "CanAttack", and  a WaitForSeconds function.







Monday, April 24, 2017

Day 38: Audio-only Game: Day 13

Today I found out that I didn't even reply to Commoble's answer. Instead I just added a reply on my question. So today, I deleted my comment, and re-posted it as a reply to their answer.
So, while I wait for the answer (again), I added some script that sets the distance of the combat raycast depending on what weapon is being used. Pressing '1' switches the distance to 3 for a sword, and pressing '2' sets the distance to 100 for a bow.
I spent the rest of the class looking for sword and bow sound effects. Next class, I will learn how to add audio to my game.

Thursday, April 20, 2017

Day 37: Audio-only Game: Day 12

So I got an answer to my question. I just need to see if it works.

So, I put the second part of the script in, but I don't know where I would put the first part of the script (the one that starts with "ScriptType"). I also don't know if I even put it in the right place.

 I replied to the answer by "Commoble" asking where I would put it. Now I just need to wait again.

Now to add to the Statistics script. I added some script that destroys a game object after 3 seconds, if its health variable is equal to or less than 0.

So when its health reaches 0, it disappears after 3 seconds.

The 3 seconds allows for death sounds and anything else that might happen when an enemy dies.

Next class I will hopefully be able to continue with the raycast script.




















Wednesday, April 19, 2017

Day 36: Audio-only Game: Day 11

I needed a way for the raycast to interact with objects. First I made a RayCastHit variable called "WhatIHit".

Next, I added some script in the "if" statement that stores the data for the item the raycast hit in the variable.

Next, I changed the Debug.Log so it would output "I hit" and then the the name of the object it hit, which I accessed through the collider of the object.


As you can see, the console is outputting "I hit terraaced1am", which is the name of the house model that the raycast is touching.

Now to have the raycast subtract health from a character. I made a new capsule object called "enemy" just to test it, and gave it a RigidBody.

I then added the Health script on to it. The script only contains the health variable, and nothing else for now.


Unfortunately I don't yet know how I would have the raycast change the variable on hit. So far, I have enough script for it to access a component, but I don't know how to specify which component, or how to change a variable in the component.

I posted a question on the Unity3D forum, so hopefully I'll have an answer in a couple days or so.

Until then, I'll add more to the Health script.















Thursday, April 13, 2017

Day 35: Audio-only Game: Day 10

Now to add a sword mechanic. I decided to use a limited raycast instead of an animation and a collider. First of all, I made a boolean called "Attack" and started it as "false". When it changes from false to true, it will trigger things like sound effects.


I then made a public float variable that will define the distance the raycast will go.

Then I made a small script that will draw a raycast for every frame that the game is active. This is really just to test how long I want the range. I also assigned a colo(u)r, since raycasts are by default, invisible.

And there's the ray.

I decided to change the distance to 3, which seems to be a decent range for a sword. No, it is not too long. You have to have some advantage in a game where you're blind.

I then added and if statement that would detect if it hit something, and then output "hit something" in the debug console.

Now it detects when the raycast hits something...or stabs a house.

Next class I will be adding script to make the raycast interact with other objects.










Tuesday, April 11, 2017

Day 34: Audio-only Game: Day 9

To add a health stat, all I did was add a public variable named "Health" in a script called 'Statistics', and set it to 100.
I don't have any combat mechanics in place to change the value, so I can't really do much more. The rest of the class I spent looking for tutorials for what I'm going to do tomorrow: adding a combat mechanic for swords and bows.
             


































Monday, April 10, 2017

Day 33: Audio-only Game: Day 8

Today I will be adding a  pause mechanic. I made a new public integer named TimeInt. This will switch between 1 and 0. I then added script that changes the integer to 1 if the escape boolean is true, and 0 if it's false. Then I added a final script that sets the TimeScale to be equal to TimeInt every frame.


This will prevent objects in the scene from moving. Afterwards I added this little bit to make the TimeInt variable start at 1, otherwise it would have nothing assigned to it to begin with.

I started running into a problem. Whenever I started the game, my character could move around. that's fine. However, once I pressed escape, it would still be able to move. And if I press escape again to get out of the menu, my character would then freeze. I decided to try using two if statements instead of an if/else.

That still didn't work, so I decided to try switching the values.

And it somehow worked. It doesn't seem like it should work, but oh well. I'll go with it.

Now I need a way to disable turning the camera when in the menu. I simply added a bit of math to the sensitivity for the camera.

This will multiply the sensitivity by whatever value the TimeInt value is. So if the value is 0, then the the camera movement value will be multiplied by 0, stopping it from turning.

Turns out I can't put a "Find" function there. Instead, I made a variable called TimeInt2, and set that equal to TimeInt. Then I used that and multiplied it.




And that still didn't work. So far, nothing I have tried has worked. I think I will leave the mouse movement pausing until later. Next class, I will be adding a health statistic.













Thursday, April 6, 2017

Day 32: Audio-only Game, Post 7

Today I will continue setting up the game menu. Last class, I moved the MenuController script to another game object to make it work. Now I just need it to deactivate/activate the menus remotely.

First of all, I decided to use tags to differentiate between different gamer objects. I added the tag "GameMenu" to the GameMenuPanel, and "Menu" to the other sub-menus.

Alright, I scrapped pretty much everything except for the "EscapeActivated" boolean, and added a single line of code: "GameMenuPanel.SetActive (EscapeActivated);"

And it works.

Now all I need to do is apply it to the other menus. They will now all deactivate when the escape button is pressed.

Testing it out:

I also quickly added a "resume" button in the 'Paused' menu. Unfortunately, I can't make the button change the "EscapeActivated" boolean, which means you have to press escape to change it to false, then escape again to change it to true to activate the menu.

Next class I will make the "escape" button actually pause the game. Right now, it just shows the menu and doesn't actually pause the game.





























Wednesday, April 5, 2017

Day 31: Audio-only Game, Post 6

First of all, I decided to make the 'settings' button work. I simply set the button to change the settings panel to "active", which makes the panel appear.

I then went to the "back" button on the settings panel, and set that to change the settings panel to "inactive"

Now I can show and hide the settings panel.

Now to set the "escape" key to show the main menu, or hide all menus. First of all, I added a boolean called "EscapeActivated" When it is 'true' the main menu will appear. When it changes to false, all menus will disappear (if the player is in-game).
Then, after a bit of experimentation and googling, I added some code that toggles the boolean whenever the escape key is pressed.

I ended up running into a problem. When I put the script on one of the menus, it won't work, because at some point the menu will be deactivated, and the script with it.

So what I'll need to do next class is make a new empty game object, and put the script on that and have the script remotely activate/deactivate the menus from there.