Monday, July 30, 2018

Day 2: Fun With Tutorials

Unity is infamous for its poor documentation.  They have a lot of tutorials, walkthroughs, and documentation available, but these are mostly out of date and/or ambiguous.

Here is a scene from the first Unity tutorial on C#:


This shows coding in Unity's old coding environment called MonoDevelop, which as far as I can tell no longer exists.  Instead, Unity opens Visual Studio when you click on code.  The first problem is that this code doesn't work in Unity today.  It doesn't even warn for deprecated code and continue; it just refuses to work at all.  Here is what did end up working.  Note that if you are reading this a few months from now, Unity will probably have changed again, and this will no longer work either.



Fortunately, Visual Studio automatically added the line "using UnityEngine," which is apparently necessary now.  As far as the middle part, I found the updated code by reading all the Youtube comments on this video.  There were nearly one hundred of them complaining that the code does not work and one brave soul who told how to change it.  Thank you, Mr. Baumgartner!





He has the "this" keyword in his code.  When I tried that, Visual Studio informed me that using "this" is outdated.  Okay, whatever.

What this code is supposed to do is, when you press the key "R," this changes the thing on the screen to red from...whatever it was before.  This script works for any object in the game it is applied to.  Notice the code uses the generic keyword "gameObject."  You write code in this generic way, then drag and drop it onto the game object you want it to work with.  For this example, I made my cube turn red.


The floor and the infinite void are not red, even though I hit the "R" key because I did not drop the enreddening script onto those objects.

Well, that was nice.

Another thing wrong with the tutorials is their selection of material.  The first video is at great pains to explain you can use the keywords "red," "green," and "blue," but it does not explain what the semicolons and colons mean, why the dots, what a renderer is.  What is with those angle brackets and parentheses?  I think if you were not already familiar with coding that this would be absolute nonsense to you.  As for me, I am still not clear what a "behavior component" is and why it is important that a script is one.

The videos cover loops, conditionals, scope, and vector math, all in 2-5 minutes apiece.  They even have a video on Quaternions!  I was amused how violent the vector video was.  Figuring out the length of a hypotenuse was framed as decided whether two people with guns with a particular firing range can kill each other.  Deciding on the torque to aim a cannon was the example for cross products.

As a curriculum, these are really poorly planned, is what I'm saying.  It is just enough to get a complete beginner absolutely frustrated.  I'm not sure why these exist.  Perhaps Unity wanted to give the appearance of helpfulness without actually devoting any funding to the project?  Anyway, sample 2D and 3D game levels with tutorials attached apparently exist, so I'm going to try those next.  Here is a link to the Unity C# Scripting Tutorials if you want to try them out:

LINK

Saturday, July 28, 2018

Day 1: Fooling Around With Unity

The time has come--the time to make a video game.  Am I skilled?  Ah, well.  Driven?  Er...  Talented?  Um.  Ingenious?  You see...

Okay, do I have a computer, and have I downloaded Unity?  YES.  The answer is YES.

Unity is a game development engine that provides a lot of tools, such as automated gravity and lighting.  It even has rudimentary AI behavior.  Most importantly, it is entirely free until your or your company starts making more than 100,000 USD per year by selling games made with the engine.  If this happens, you have to license the software, but you still don't have to pay royalties.  Well, that is a problem for future me.  Unity connects with Visual Studio where you can write your code in, typically, C#, but you can also use JavaScript (technically an offshoot called UnityScript), or possibly some other languages.

I, of course, know none of those languages.

Alright, first things first.  This is going to be a 3D game, so...


Huzzah!  I'm not the very first clueless person to fire up Unity.  Oh!  I forgot the most important step:

This is the most important step.


This means that the "finished game" will not attempt to send information from the user back to me, the developer.  The silly file I'm about to make will never have users, but it's important to take a stand sometimes.  Um, I actually have no memory of learning what Unity Analytics are and how to turn them off, so I'm going to assume that the knowledge was floated to me from my alter-universe counterpart who is already a successful game dev.  Good job, me!


Unity starts you out with a skybox (the blue thing), a sort of grey void that goes down to NaNfinity, and some, um, lighting.  Also, there is a camera present, and you can see its viewpoint in the lower half of the screen.  That window, the "game window" is supposed to be what a player would see.

The "creating floors for level" thread up there was super helpful.  I have added an eye-blisteringly white floor.  That is the floor-shaped thing in the picture*.  I have also figured out how to add a cube to the scene and turn on gravity.  For reasons that I'm sure will be explained later, Unity uses the Y-axis for "up," so I had to move this 1x1x1 cube 0.5 units Y to make it rest on the floor.

Okay, well...  *whew*  It may be time to take a nap.  I'm not used to accomplishing this many impressive things in one day.

*Just in case you found this post by asking Google how to make a floor, add a Plane to your scene.  It is in the Game Object > 3D Object folder.  It seems that by default, objects do not fall through a Plane, so that's nice.

Shuffling Cards When You Are a Computer

The last time I programmed anything, programs started at the top of the Main function and proceeded to the bottom...if the Unix terminal was...