I have dared to step into the world of GUI!
This is an attempt of making a flexible GUI system, in which you can drag spells from one spot to another. Then from that spot, you can click the button and you would cast the spell that you dragged into that spot.
Here’s the script called “testScript”
enum SpellSlots {
inActive,
slot1,
slot2,
slot3
}
//static var doScript : boolean = false;
var _state1 = SpellSlots.inActive;
var _state2 = SpellSlots.inActive;
var _state3 = SpellSlots.inActive;
var bool1 = true;
var bool2 = true;
var bool3 = true;
var clickedButton = false;
static var targetSpell : String;
static var spellName : String;
private var spellSlot : SpellSlots;
function OnGUI () {
// For combat use
if(bool1){
if(GUI.Button(Rect (100, 10, 50, 50), "")){
if (clickedButton){
_state1 = SpellSlots.slot1;
bool1 = false;
clickedButton = false;
}
}
}
if(bool2){
if(GUI.Button(Rect (100, 70, 50, 50), "")){
if (clickedButton){
_state2 = SpellSlots.slot2;
bool2 = false;
clickedButton = false;
}
}
}
if (bool3){
if(GUI.Button(Rect (100, 130, 50, 50), "")){
if (clickedButton){
_state3 = SpellSlots.slot3;
bool3 = false;
clickedButton = false;
}
}
}
// For test use
if(GUI.Button(Rect (20, 20, 50, 50), spellName)){
clickedButton = true;
}
if(bool1 == false){
if(GUI.Button(Rect (100, 10, 50, 50), spellName)){
Debug.Log("Clicked button 1");
}
}
if(bool2 == false){
if(GUI.Button(Rect (100, 70, 50, 50), spellName)){
Debug.Log("Clicked button 2");
}
}
if(bool3 == false){
if(GUI.Button(Rect (100, 130, 50, 50), spellName)){
Debug.Log("Clicked button 3");
}
}
}
// When a state is activated
function Activated () {
spellScript.doScript = true;
}
function Update() {
if(clickedButton){
clickedButton = true;
}
if (_state1 == SpellSlots.slot1){
Activated();
}
else if(_state2 == SpellSlots.slot2){
Activated();
}
else if(_state3 == SpellSlots.slot3){
Activated();
}
}
And here’s the script called “spellScript”
var spellName = "";
private var thisObject;
//private var thisScript;
static var doScript : boolean = false;
var callScript = "";
function Update() {
testScript.spellName = spellName;
//testScript.targetSpell = thisScript;
thisObject = this.gameObject;
//thisScript = this;
if(doScript == true){
GetComponent(callScript).enabled = true;
}
}
I am looking for some kind of way to make testScript identify how many versions of spellScripts there are. So that there can’t only be one spell available. And I also want the option to have different spells (scripts and models) assigned to one game object. Besides that, I don’t know how to make rows of buttons without having to repeat myself, or make a new button next to another when f.ex. you get a new spell.
I hope I’ve been specific enough and that you guys wanna help me ![]()
Edit: It would be nice if you could give me some tips on this or maybe show me where I can learn to do this - I am very new on this subject so I can’t read and understand other GUI scripts if they’re advanced.