Friday, August 31, 2012

Bugz: My spawn or your spawn?

Jeez, spent the longest time trying to figure a bug in Unity where 'spawnpoint' wasn't defined. Didn't quite figure out it was a transform value I'd set up in the thing I was trying to instantiate - I kept thinking I hadn't set up the instantiate properly and was going through all sorts of hoops and variations trying to figure what I did wrong!

Eventually clicked and had to figure a way to plug the player value into the instantiated object.

Now I can have the ghosts spawn after a certain position is passed, for a bit of a 'Argh!' effect - which the characters dialog is set up to give as well!

Thursday, August 30, 2012

Unity: Counting substrings inside a string

Tying into the previous post, it seems unity has no actual command for counting the number of instances of a substring in a larger string. I've been hunting around for ages and having found no actual command, I've decided to show some code that does it. The code is about as tight as you can get it without it actually being a command!

As with the last post, I'm using /n instead of \n. This is because when the interpretor looks at \n it decides to ignore the n part, making the search only one character in length. The previous post lists the way you can easily convert /n to \n. I know, it sounds annoying - if I were reading this, I'd think it was annoying. But given that unity gets uppity if you try to enter strings into the inspector (ie, it just wont do line breaks if you do so), you're probably gunna have to end up switching /n to \n anyway. It's just a simple replace command anyway (okay, fine - if you don't want to look at the other post replace is as simple as: guimessage = guimessage.Replace("/n", "\n"); )

But I make excuses like a man! Now, onto the search code!
    var stringtosearch = "this is the test string /n with several /n line breaks in it";
    var searchingfor = "/n";
    var substringspresent=0;
    var searchextent=stringtosearch.Length-searchingfor.Length; // makes sure we don't search past the end of the string!
    for (i=0;i<=searchextent;i++)
    var sectionscanned=stringtosearch.Substring(i,searchingfor.Length);
    if (sectionscanned==searchingfor) substringspresent++;
    print (substringspresent);

Unity: Getting new line in inspector entered strings to work

It's weird - in a script I had some text defined with \n to create a new line and that worked out.

But when I defined an array of strings and filled them in in the inspector, it'd just show the \n instead of creating a new line!

So here's a solution:
guimessage = guimessage.Replace("/n", "\n");
 In your strings, have /n instead of \n. It'll replace them and for some reason, they then start working! It puts the special magic back in!

Gimp Layer Transparency Tip

It's something I get hooked on occasionally. If you want to make a layer overall have some transparency, in the layers dialog box itself there is a slider near the top for opacity. Once again I was hunting through menus trying to find that option!

Wednesday, August 29, 2012

Reward Systems: One vote, one party

There's something that bothers me about the reward structure for a summer class, described over at play this thing.

I'm not quite sure what it is. I'm thinking that it's the complete lack of choice - that point systems can act like voting - and you vote/collect points for what you want. But a 'set' system - it's like a one party system, but the more you vote for them the better off you are.

Not sure I like game systems that promote monomaniacle behaviour. It really is all or nothing. You can't sway the sysem - your either a devote, or you leave it entirely.

Not commenting there, so as to reserve the cynicism a bit.

Friday, August 24, 2012

Piracy: The great narcissistic and selfish superstition of our times?

I've said this before and I wonder:

If people were forced somehow to either A: Buy the product or B: Do without it, how many of them would actually do A?

I think alot of 'concern' around piracy is simply narcissistic self flattery that all them scumbags would buy the damn product, if you could force them.

But really, how many would?

If it were somehow tested and a large percentage would, okay, there's some validity in it.

But I rather suspect alot of people simply wouldn't buy the product.

Which means to continue with the idea of piracy would be the worst kind of petty selfishness - that even if it costs you nothing, other people just can't have X, just because.

It makes me wonder if the idea of piracy is one of the great superstitions of our age, powered long by our own bulbous egos?

Guess what, at the very least they wouldn't all have bought your product. Stop fooling yourself.

Indeed you probably sell more than you otherwise would, from indirect advertising (some people try before they buy).

Thursday, August 23, 2012

Unity3D : Making a Health Bar

Jeez, I was around when game magazines made jokes about the idea of a 'Health Bar' being some kind of spa in Europe or something. It was all new fangled back then...

Anyway, I had a heck of a time recently looking up a way of making a health bar in unity. I have found a way - not quite perfect, as the bar doesn't shrink perfectly when at low health. But looks nice enough and if the characters that low, they probably will die before they notice the problem. Maybe at some point in future I'll suddenly discover a better way to code it. Anyway, so this is the basic code:

var playerHealth : float = 100.00; // use your health var here
var playerHealthMAX : float = 100.00; // use your MAXIMUM health var here (to calculate a percentage from)
private var playerHealthBar : float; // just a var that holds playerHealth as a percentage
var customGUISkin: GUISkin;

function OnGUI ()
    playerHealthBar = playerHealth / playerHealthMAX;   // playerHealth as a percentage
    if (playerHealth > 0)
       GUI.Box(Rect(10, 10, 200, 20),""); = customGUISkin;
       GUI.Box(Rect(10, 10, (200 * (playerHealth / playerHealthMAX)), 20),""); // health bar is 200 wide at maximum health = null; // put the back to default
 You also need to make a, which you can do by going to your project overview, clicking create and at the bottom there should be the option for

Go into it and open up the box options. Near the top you'll find 'normal'. Open that up and you'll find a background option. It's here you can drag a graphic in - in this case, probably something 200 pixels wide, 20 tall.

Then make sure you add this script to an object (like your main camera), then in the inspector make sure to drag the you made into the slot for custom GUISkin.

Any problems, leave a comment! :)

Tuesday, August 21, 2012

Massively Forgot what I was doing...

Every time Lord of the Rings Online patches, I kind of stop playing. I try and hedge it to the end of the month, so as to not use up my data limit.

But then...I've lost track of what that next thing I wanted to do was. Never mind the auction house mails that have expired in the mean time (I could just shrug at their loss - but then, that's kind of shrugging at the game in general).

Maybe I'll just bring up my lotro and enter the lottery they have - and if I win, hey, maybe I'll log in to see what I got!

Monday, August 13, 2012

Some good Unity 3D tutorials

I was refered to some great unity 3D tutorials recently. I've done the point and click tutorial and am currently on the space shooter tute. Very much a step at a time stuff, though you have to squint at the code in the video. You'd pay $$$ to get this from a course.

Sunday, August 5, 2012

Fight Cycle: Update

Quite a few additions since last time - A gym, a yard where you can grow food to eat or sell the excess, and a moves system you can optionally use (by default it's on). I really like the yard system because each click on the fight, main or gym pages is recorded and each day more food grows in the yard, relative to it - then any extra that builds up is sold to an NPC store, which sets up how much game money will be distributed at the end of a fight cycle. I really like how the economy rises from actual people and their actions!

Originally I posted this over here, should have done it here first otherwise google might think I'm just cutting and pasting others content! When it's my own, but I always seem to type it up somewhere else first! Bad habit!