Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Friday, March 11, 2016

Troubleshooting

The presenter in the Scavengers tutorial barrels along faster than I can type, and I'm not slow.  I was pretty sure I'd miss something.  And I did.  My food and soda wouldn't pick up and it took me a long time to realize I'd misnamed my method with 2d instead of a 2D.

But what really got me wasn't something I could control.  When my level was resetting, it wouldn't recreate the board.  I changed from a deprecated method to the new loadscene version.  And then I started putting in debug.log statements (didn't I say this felt like old school VB once before?).  After trying to narrow it down, it appeared my Awake function wasn't triggering, so the board wasn't repopulating.  I compared their completed version with my version of the script, and the prefab, everything else, all to no avail.  Finally, in this five year old post (long before the current version of Unity) someone mentioned that Awake() doesn't always refire and you have to code it up under OnLevelWasLoaded() to catch logic after the first time.  I dropped it in there - cut and paste rather than appropriate refactoring - and success!  So for anyone else who's getting Awake() or InitGame() events that aren't firing when they expect them to, OnLevelWasLoaded() is a good place to call your logic again to be sure it triggers.

You can see the affect of the bug on not rebuilding subsequent levels in the video.

Tuesday, February 23, 2016

Unity Bug #2 - That was Fast (and funny)

Thought I'd be smart and fix the increasing difficulty Vector3 issue by just making the velocity of the asteroids faster and faster based on the wave count.  So I exposed the wave count on the Game Controller and accessed it via the move script where asteroids keep set their velocity based on a public property.

I forgot to account for my wave array being 0 based.  I failed to account for the fact that my shots and asteroids were tied to the same velocity/move script, meaning my bolts go faster as the asteroids go faster.  Perhaps not a bad thing, although strange.  And my ship's movement isn't tied to the same movement script, so it doesn't get faster as the rocks start to shoot down the screen at breakneck speed.


Friday, February 19, 2016

Destroy the Object

I'm tempted to use Unity3d as an interview tool for intern/new grad candidates as a great example of the dangers of not getting rid of your objects.  It was cool to see it hang on to shot objects forever because they never ran into a border which would de-instantiate them. Why are interview candidates not infinitely smart compared to me when I was looking for a job?  Seriously - with tools like this, you should be able to talk for hours.  And hours.


Monday, April 11, 2011

Kinect for .NET

Can anyone tell me if I have to buy a special cord - e.g. this one - in order to hook my daughter's Kinect to my Win7 laptop so that I can code against it for fun?  I told Pooteewheet I'd like to code up a game based on obscene gestures and I mean to do it.  In particular, I'd like to code an app that tells you what binary value you're holding up if you flash it a few fingers.  I suspect that might be too granular, but it would be fun to try.

I got the drivers and code installed today, only to discover I couldn't plug the thing in.  I put a question out to the guy who presented at Code Camp yesterday (I missed it - I was at another presentation), but haven't heard back yet.

Resources:

Friday, March 25, 2011

Smart Girl!

Eryn wants to know how to code.  I taught her a little bit of Ruby once upon a time (we played with Shoes), but she asked if I'd teach her C# because she knows that's what I used when I did programming for a living (I haven't given her the article "Why We Don't Hire .Net Programmers" to read).  We started out with a simple Console app so we could play around with loops and writing to the console.

int counter = 0;

            for (long i = 1; i <= 100; i++)
            {
                Console.WriteLine(i + " My name is Eryn");
                counter = counter + i;
            }
            Console.WriteLine("Counter is: " + counter);

She was having fun increasing the counter value by a magnitude and watching it hop from 5050 to larger numbers.  But after she threw in a million and waited for the loop to end, she asked, "Hey, why isn't the number as consistent as the other numbers were?"  That's right...she intuitively debugged the fact that the int datatype wasn't sufficient to hold the sum of all the numbers up to a million without creating a problem in the output.  We discussed bugs and what a bug like that might have meant if you were trying to write code for the space shuttle.  Fun!