Make an Turn-Based RPG Fighting Game in Unity
Learn how to make a 2D RPG turn-based battle system with Unity. Final Fantasy Tactics, XCOM, Divity, Chrono Trigger all use a turn based battle system. It is part of what makes those game so excellent. In this tutorial I walk you through each step of making a 2D RPG style battle system in Unity. All the assets are free to use and the code is provided as well. Some of the code is below, to access all assets and code click the assets button. Download the assets, follow along and make something awesome!
Fighter Action
Make Button
Plain Text
Fighter Action
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FighterAction : MonoBehaviour
{
private GameObject hero;
private GameObject enemy;
[SerializeField]
private GameObject meleePrefab;
[SerializeField]
private GameObject rangePrefab;
[SerializeField]
private Sprite faceIcon;
private GameObject currentAttack;
void Awake()
{
hero = GameObject.FindGameObjectWithTag(“Hero”);
enemy = GameObject.FindGameObjectWithTag(“Enemy”);
}
public void SelectAttack(string btn)
{
GameObject victim = hero;
if (tag == “Hero”)
{
victim = enemy;
}
if (btn.CompareTo(“melee”) == 0)
{
meleePrefab.GetComponent<AttackScript>().Attack(victim);
} else if (btn.CompareTo(“range”) == 0)
{
rangePrefab.GetComponent<AttackScript>().Attack(victim);
} else
{
Debug.Log(“Run”);
}
}
}
Make Button
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MakeButton : MonoBehaviour
{
[SerializeField]
private bool physical;
private GameObject hero;
void Start()
{
string temp = gameObject.name;
gameObject.GetComponent<Button>().onClick.AddListener(() => AttachCallback(temp));
hero = GameObject.FindGameObjectWithTag(“Hero”);
}
private void AttachCallback(string btn)
{
if (btn.CompareTo(“MeleeBtn”) == 0)
{
hero.GetComponent<FighterAction>().SelectAttack(“melee”);
} else if (btn.CompareTo(“RangeBtn”) == 0)
{
hero.GetComponent<FighterAction>().SelectAttack(“range”);
} else
{
hero.GetComponent<FighterAction>().SelectAttack(“run”);
}
}
}