Blog

Easy Transform

Well if you deal with Unity all day you probably faced this situation: “This object looks good here, I want to copy and paste all these other objects to that position”, and I lost count how many times I saw level designers writing on a paper or using Text Edit or (Note Pad) to type on each object the saved position.

default
Unity’s default transform inspector

I started thinking about develop a tool to solve that problem when I saw NGUI reseting options on transform panel. Then I though well it should be nice with I can copy and paste on the same place, but I keep the idea stored.

Unity inspector panel
NGUI transform custom Editor.

Before we at Secret Weapon used another editor tool which you have to click on Editor tab on top of screen and then again to paste desired transform option. All team complain about that, but as always I have thousands things to do and keep the solution for another time.

One day the level designer came to me and said: “Why Unity doesn’t make an easy way to copy positions, rotations and scales?” I answered him: “Today it’s your luck day”. Few hours later I came up with that tool for him to use, he was doing a exhaustive level construction scene in Unity. You can image his happiness 🙂

easy t
Easy transform customised panel

The Tool

  • Easily reset position, scale and rotation with one click, by clicking on POS, ROT, or SCALE.
  • Also copy and paste transform with one click, by clicking on C or P of respective type.
  • Undo supported

Download it!

easy transform

 

Pick one of our secret weapons that we use everyday!

Implementing Game Modes

Hey, today I’ll show our newest game, called Fire for your Life, a twin brother of already released Race for your Life. As you may know 🙂 or not yet :(, it’s a tank battle game with retro style, multiplayer and cross platform. More specifically I’ll demonstrate its game modes, which are five:

  • Death match – last player in the map wins.
  • Capture the flag – player with more captured flags wins or the last survival wins.
  • Domination – player with more bases wins at end time or the last survival wins.
  • Protect base – each player has a base, if it is destroyed his tank dies, the last survival wins.
  • One shot one kill – each shot is mortal, the last survival wins.

So after that said, you noticed that each mode share one specific rule, the last tank is the winner. The point is that usually in Unity, we programmers blind ourselves in some basic object orientated programming. For example this is a good case to use a base class with common properties and functionalities.

public class GMBase : MonoBehaviour, IGameMode
{
    protected bool finished;

    public virtual void StartGame()
    {       
        finished = false;
        //your start logic
    }

    public virtual void CheckEndGame()
    {
        if (finished)
            return;
        //your check end game logic, could be time, players life, etc
        FinishGame();
    }

    public virtual void FinishGame()
    {
        //call managers to handle end game, display game over, etc
        finished = true;
    }
}

Base Class

Also provide an interface that forces classes to implement game mode functions.


public interface IGameMode
{
    /// <summary>
    /// Called by game controller when game is initiated
    /// </summary>
    void StartGame();

    /// <summary>
    /// Called by game controller on a loop to check end game
    /// </summary>
    void CheckEndGame();

    /// <summary>
    /// When game really ended, it call Game Controller
    /// </summary>
    void FinishGame();
}
Interface

Later we can create another script class that handle Domination game mode logic. Note that we don’t need to write all code checking tank deaths and so on, keeping our code clean and lean.


public class GMDomination : GMBase
{
	private float timer;
    
	public override void StartGame()
	{
		base.StartGame();
		timer = 0;
	}

	void Update()
	{
		timer += Time.deltaTime;
		//Check Winner after X seconds passed		
	}
}
Domination Game Mode Class

So next time implementing things like this I hope you can use this approach to help your game development. Here is dev video showing it in action.