Skip to content

Instantly share code, notes, and snippets.

@kurtkaiser
Created July 2, 2020 19:52
Show Gist options
  • Save kurtkaiser/951ac7defa25502dfd2f3ec61f615852 to your computer and use it in GitHub Desktop.
Save kurtkaiser/951ac7defa25502dfd2f3ec61f615852 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 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");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment