Skip to content

Instantly share code, notes, and snippets.

@kurtkaiser
Created July 2, 2020 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurtkaiser/d56c206a9331a22eb933894a3811e480 to your computer and use it in GitHub Desktop.
Save kurtkaiser/d56c206a9331a22eb933894a3811e480 to your computer and use it in GitHub Desktop.
RPG battle system, this game was built for a YouTube tutorial.
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");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment