• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ComputerTopGames · Apr 08, 2012 at 10:48 PM · turn-basedattributeunits

Turn-based strategy game...where to begin?

Hi everyone! This is my first foray into the realm of game programming. My goal is to make a simple, turn based game.

All I want to do is have two-six units on a board that can attack one another. These units will have attributes that will affect the combat (think of like a an old table top game with miniatures).

Where should I start? How do I make my own units have the attributes I want?

Thanks in advance for all your help!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Topthink · May 18, 2018 at 11:52 PM 0
Share

Good Luck !!! I love a good turn based strategy game. I've been into that since the old Avalon Hill board games (60s, 70s, 80s of the last century). They are very fun if done properly. I'd love to see what you come up with...let me know if you need a play tester.

Best wishes!

4 Replies

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by save · Apr 09, 2012 at 01:35 AM

Welcome to the most awesome site for help regarding Unity then! This is a very vast topic with many puzzle pieces but it's also a very good question. I'll try to answer as good as I can and hopefully you'll find some of the tips to come in handy.

Try it out before you even start

You might want to draw the game on paper or even do a live test with people you know who can act out the game. It's a bit unconventional but you'll get really good feedback from them and you'll see in a very early stage if your idea will work as a game. Now this applies to mostly all games or projects but perhaps even best for a turn-based one. You'd want to have all the rules ready before you try it out in an environment free from bytes, so try to structure the rules in a flowchart - If a player does that with these attributes it will affect the other players in this way, and so forth. This will come extremely in handy when testing, but mostly for the actual development process. I usually use Xmind as it gives a fast visual result with what's connected with what and it's easy to extend parts later.

This also forces you to elaborate with the elements of the game before even opening up your first script document, it's a huge advantage to have later! Too many times things gets added or reworked in the middle of the process which sometimes kicks back development for weeks, this happens all the time in the industry as play testing usually brings back some nasty results here and there.

It's important you ask yourself, who is this game for and what should it accomplish. Is it something that would target a wide variety of table players, beginners or more advanced table players or even if it's just a small project for you to learn scripting, then so be it. Once you have the answer to this, you know what level you should aim for in both graphics and interactions, nevertheless the feedback it would have to the player too regarding information on-screen.

Good to go

So perhaps you saw some flaws during testing and fixed them, hopefully you and the people involved also saw that this was a fun game - then you're good to go! You'll also have a first structure where the rules already are set and a workflow for the elements of the game. If this is a serious/live project, you would have a flowchart for the development process too where you'd have a timespan connected to each step. This is of course very hard to do in the beginning with next to none experience in the field, so therefore it's good to time everything you do for the first time. Have a document ready where you just put a number of hours next to the functions (in the bigger picture) and at the same time write down how you solved them, perhaps add some links etc so you can backtrack everything. Maybe this sounds really anal, but you'll thank yourself for doing so as you always can go back and look something up and continue on a breadcrumb path later. Doing this in the code isn't the best, comments in code tend to clutter everything up and it gets really hard to read after a while.

Make sure you start fresh, create a new project in Unity and be very tough on yourself when it comes to structure, where every component such as meshes, textures, materials, audio and scripts goes in their folders and subfolders. A project without structure won't be fun to revisit, think of it as a space where you'll live in the nearest months.

Scripting in Unity

It doesn't really say whether you have earlier experience in Unity 3D, so just in case, these places are good to have a bookmark on:

  • Unity Scripting Reference

  • Unity Forums

  • Unify Community (where this article is just plain awesome if you use UnityScript)

  • .Net framework

  • and this place

And not so surprisingly Google will help you with most of your answers before they become too detailed to your own project.

You have to decide whether you're a C#-, UnityScript- or Boo-type of person, once that's established you're ready to create a fresh scripting document. C# and UnityScript is easiest to find documentation for and I would say UnityScript is easiest for a beginner. If you go with UnityScript (which is also referred to as JavaScript as it is quite similar) I would recommend you to always disable dynamic scripting using #pragma strict in the top of your document. This is crucial for development further on and it's best you learn to set the type (as in the type of component) for your variables from the beginning to make your code faster and more reliable.

It is crucial that you cache your components, it'll also be easier for you to reuse them keeping this in mind from the beginning. Caching can look like this (UnityScript):

 static var gameObjects : GameObject[]; //Type is GameObject where [] states that this is an array
 function Start () {
     gameObjects = GameObject.FindGameObjectsWithTag("Player"); //Finds all GameObjects tagged "Player"
 }

You can now reuse that from anywhere inside the level by calling TheScriptName.gameObjects; as we made it a static variable. Variables come in three types where they're either public, static or private. A public variable will show up in the Inspector and you can alter it inside Unity, a private won't show up in the Inspector and will have limited accessibility through scripting and a static is accessible from any other script. The most common use for a private variable is when an attribute for a GameObject shouldn't derive from anywhere, just live in its own space and handled from within its script separate from any other instances of this object. Static variables are most commonly used for singletons where there only is need for one variable which should be accessible from anywhere.

Some of the most common variables:

 var floatingValue : float = 0.1337;
 var integer : int = 1337;
 var aBool : boolean = true;
 var vec2 : Vector2;
 var vec3 : Vector3;

Keeping these babies public or private will have you all set for setting their individual attributes.

With that being said, a turn-based game would very early in the development process demand that you have an insight in how arrays work and what type of arrays you should use. Together with the arrays you will have to know how to iterate through them which most commonly is done with a for-loop or a while-loop.

 //This loop gets all Scripts from our gameObjects and sets aPublicBoolean to true
 for (var i : int = 0; i < gameObjects.Length; i++) {
     var thisObjectsScript : ScriptName = gameObjects[i].GetComponent(ScriptName);
     thisObjectsScript.aPublicBoolean = true;
 }

So basically, to alter another objects attributes/variables, you use GetComponent (the more cached the better) and pick up its script then alter the variable, theScript.theVariable. For instance:

 #pragma strict
 
 static var theScripts : ScriptName[];
 var strength : int = 10;
 var health : int = 100;
 function Start () {
     var i : int = 0;
     for (thisScript in gameObjects) {
         theScripts[i] = thisScript;
         i++;
     } 
 }
 function OnAttack (whichOne : int) {
     if (theScripts[whichOne].strength>strength && theScripts[whichOne].health>health) {
         health-=10;
     } 
 }

Note that this is just a scripting example, this would differ widely on your implementation.

Which brings us to functions, you will most likely need to create your own functions immediately when starting to script a turn-based game. A function can also be static which is good to remember.

 //This is a function that takes an int and returns a boolean
 function IsThisTenOrHundred (passedValue : int) : boolean {
     var thisValue : boolean = false;
     switch (passedValue) {
         case 10: thisValue = true; break;
         case 100: thisValue = true; break;
     }
     return thisValue;
 }

The function can now be used by calling this:

 var zeroToHundred : int = Random.Range(0,100);
 if (IsThisTenOrHundred(zeroToHundred)) Debug.Log("Yes I'm either 10 or 100");

Yielding is mostly important in many aspects, sometimes you need to yield for a certain element to become true, or just wait for a certain amount of seconds or frames.

 while (waitingForPlayersTurn) yield;

The boolean variable waitingForPlayersTurn could for instance be triggered when another player has made a move or has pushed a button.

It's also common to keep a script from continuing if a certain condition is or isn't met, for instance:

 if (waitingForPlayersTurn) return; //All script below this won't execute if waitingForPlayersTurn is true

A player and/or unit should be defined in an array so you could add more or subtract at any time, then you could set up your code like this whenever you need to call a specific event for a specific player:

 static var thePlayersTransform : Transform[];
 static var currentPlayersTurn : int = 1;

 thePlayersTransform[currentPlayersTurn].position += Vector3(10,0,0); //Moves player one 10 units from current position

You most likely need a manager to your levels which keeps track of everything, the key here is to use an object with DontDestroyOnLoad(). A manager is simply a script with static variables and functions (mostly) on an empty GameObject that follows the entire game through and keeps track of such things as scores, number of players and other objects that is crucial to remember on level loads.

Make sure to bring your time machine

Always keep several backups of the project somewhere else. Dropbox is a quick and pain free way of doing so, where you could zip the project every week - or after certain amount of hours you've continued to develop - and just drop that in a folder. Never keep backups on the same hard drive as you develop (which kind of speaks for itself).

If you want to test out certain things in Unity, have a side project for that where it's ok if everything blows up. Duplicating the project is as fast as writing bytes to the hard drive, which can be good to remember. :-)

Dont forget

  • Use simple dummy objects to test your code with.

  • It's easier and brings more life to the projects if you team up with someone, there's always good people looking for projects here.

  • We will always stick around - keep in mind UnityAnswers is a specific-issue-Q/A site.

I hope, as this tended to become quite a massive answer, that you feel a little bit more assured in what direction to head. I wish you the best of luck and hope to play an awesome new turn-based game in the nearest future!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Apr 09, 2012 at 01:49 AM 3
Share

A for-loop lives in its own space and has to be iterated before the frame ends, a while-loop can continue over several frames.

Not true; for loops and while loops are basically identical. They are just different ways of writing the exact same thing. There is absolutely nothing at all special about a while loop (although due to the syntax difference, you have a little more control in a while loop).

 var i = 0;
 while (i < 10) {
     print (i);
     i++;
 }

 for (var i = 0; i < 10; i++) {
     print (i);
 }
avatar image save · Apr 09, 2012 at 02:08 AM 0
Share

Gosh you're completely right, good thing you pointed it out. I blame the 4 am clock. :-)

To iterate over frames you use yield in a for- or while-loop.

avatar image Ash-Blue · Aug 18, 2013 at 08:33 PM 1
Share

Don't use Dropbox for many reasons. Use Github.com, its the choice for most programming professionals.

avatar image
0

Answer by Belangia · Dec 22, 2015 at 08:40 PM

 using UnityEngine;
 using System.Collections;
 
 public enum Round
 {
     Info,
     Move,
     Attack,
     Item,
     Pickup,
     Processing
 }
 public class TurnScript : MonoBehaviour
 {

 //Other Classes that handle actions;
 public  Turn_Info TII;
     public Turn_Move TM;
     public Turn_Attack TA;
     public Turn_Item TI;
     public Turn_Pickup TP;
     public Turn_Scene TS;
     public Round turn = Round.Info;
     void Update ()
     {
         switch (turn) {
         case Round.Info:
         //Tool Tips, Pause, ext. 
         TII.InfoLogic();
             break;
         case Round.Move:
         //Move logic and anything pertaining to movement actions with characters.
             TM.MoveLogic ();
             break;
         case Round.Attack:
         //Damage step, assigning attackers and taking actions.
             TA.AttackLogic ();
             break;
         case Round.Item:
         //Handle Items and inventory, or something invoking use of items. Levers,buttons,doors ect.
             TI.ItemLogic();
             break; 
         case Round.Pickup:
         //Interactions with Dropped items
         TP.PickupLogic();
             break;
         case Round.Scene:
         //Animation logic with events in the level like talking, walking, ect.
         TS.SceneLogic();
             break;
         default:
             break;
         }
     }
 }


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by div5yesh · May 18, 2018 at 09:53 PM

You can get started with a simple code example here https://medium.com/@div5yesh/turn-based-multiplayer-games-in-unity3d-using-unet-abcd8360ddd5

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MacDx · May 19, 2018 at 12:11 AM 0
Share

@div5yesh please do not bump such old threads. There has been an accepted answer on this post since April 09, 2012. There is no need for further input here.

Regards

avatar image
0

Answer by remedios · Mar 13, 2020 at 02:11 PM

This is a brilliant tutorial that walks you through building turn based scripts and game using the UI tools. https://learn.unity.com/tutorial/creating-a-tic-tac-toe-game-using-only-ui-components

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Attach Attributes/Description to Scripts 1 Answer

Custom attributes? 2 Answers

Problem with interfaces and Unity Networking Attributes 0 Answers

Make Unity attributes like [range] work together with inheritance in ScriptableObjects 1 Answer

Help with array collision script ! 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges