Main menu

Tag Archives: unity3d

I’m going to be honest, I really should be doing this more often. Basically, this post will show what has been done up until now. I’ll go over the tiles and their purpose as well as code sources. I’ll go into more detail of each section in later posts.

Source Tile

The source tile is the life-blood of this game: it sends out ‘power’ by pulsing at a set amount (0.5 seconds while debugging; 1 second most likely in the real product). Any tiles that can receive power and are turned on will receive power and pass on to other tiles.

Each source pulse has a unique signature (as unique as a 5 digit number can give) so that each tile can only receive power once from each signature. Basically, if a level becomes really large, I wanted to make sure that activatable/goal tiles don’t become self-powered without use of the source tile.

Activatable Tiles

Activatable tiles have been split into two parts: ActivatableTile and Powerable.

ActivatableTile

There are a few things that ActivatableTile handles: Material changes, audio, and collision with the player. There are 3 states for Activatables: off, unpowered, and powered.

Material Changes

All the materials are set using the Inspector. The two scenarios that cause a tile to change material are collision and power state changes. However, technically, both scenarios are routed through the Powerable script to allow a single point of change (“Change it once, change it everywhere” mantra).

Audio

The logic that handles tile audio is similar to the material change. If a material is changed, a sound effect will play. There are four sounds that can happen instead of the three material changes (off -> unpowered; unpowered -> powered; powered -> unpowered; and ANY -> off). I plan on using some kind of audio manager later in development, but I like to make things work first.

Collision with Player

Collision with the player will cause a state change in power, toggling between off and unpowered. There is also a timer associated with the collision to make sure the player doesn’t activate the OnCollisionEnter function more than once within that period.

Powerable

I split this class out from the functionality of the activatable tiles so that I could use it for other tiles later, and also to keep my sanity because it was getting to be very intertwined and convoluted code.

Powerable keeps a current state and last state for its power state, as well as a flag for if the current state was changed. This helps other tile classes react to state changes better. There’s also timers, last power signature received information, and the ability to detect neighbor tiles with Powerable scripts attached.

Goal Tile

The goal tile is relatively simple. It receives power, adds it to a total, drains at a certain rate, and declares victory when its power goal has been met. Right now, the only visual indicator of power is a light source whose intensity is changed according to current power levels.

Whew! It’s been pretty crazy working on this tower defense so far. It’s been almost two weeks since I’ve gotten a post up here. Work has been stupid busy, along with real life and looking for an actual development job. So, here’s the progress update!

Towers can now be selected with the mouse. A window will pop up on the left side and show its stats.

Towers can change targeting priority through the tower selection window.