Overwound

Code

On this page you'll find various code-related topics, Unity scripting tips, AI musings, etc.


Keep Your Variables Tidy

In scripts with lots of variables, keep your inspector tidy by grouping related variables together in classes like this:


class GameOptions
{
	var narrative : boolean = true;
	var vSync : boolean = true;
	var musicVolume : float = 1.0;
	var effectsVolume : float = 1.0;
};
var options : GameOptions;
	

This can help keep your code more readable and help you remember variable names, too. If a script gets too big though, it's probably time to break it up into smaller scripts.


Mesh Tools

I'm working on a set of procedural mesh generators that plug in to the Unity editor. The purpose of these is just to generally help in the rapid development and prototyping of levels, without having to switch out to a 3D modelling package and keep tweaking things to fit. As well as more flexible versions of planes, cubes and cylinders, I'm working on staircase builders.

I'm also hoping to get adventurous and make a lathe and extrude tool, but I think I'll stop short of recreating Max and Maya inside the Unity editor.

Here's a couple of work in progress screen shots:


Particle helper

When you select particle emitters in the Unity editor they start simulating in the scene view. Sometimes this gets in the way of further editing and I couldn't find a way to stop them doing this. It's probably there somewhere, but as an experiment in editor scripting, I wrote a quick javascript function to clear these particles. This bit of code needs to go in the Editor folder (see the scripting reference for more info).

 @MenuItem ("Particles/ClearParticles")
 static function ClearParticles()
 {
	 var emitters = FindObjectsOfType (ParticleEmitter);
	 for (var particleEmitter : ParticleEmitter in emitters)
	 {
		 particleEmitter.ClearParticles();
	 }

	 // clear selection
	 Selection.activeTransform = null;
 }
	

It clears the selection afterwards so that the particles don't start again (until you next select the particle emitter and start cursing again).


© Copyright 2011 Overwound Entertainment. www.overwound.com