This is exactly what the title says. I have a array of a custom class I made called Spell. Spell has multiple variables in it and one of them is called Icon. I need to get the Icon (Which is a Texture2D) from all of the elements in a array called actions and display it as buttons in a GUI group. I will put the code bellow.
var controlTexture : Texture2D;
var texturetodisplay : Texture2D;
var openPic : Texture2D;
var Open : boolean;
var Self : GameObject;
var Class : PlayerClass;
var Abilities : Spell;
var AvaibleAbilities : Vector2;
function OnGUI ()
{
if (GUI.Button (Rect (1300,850,200,200),controlTexture,"")){
Open = true;
}
if(Open){
GUI.DrawTexture(Rect(300,50,1200,800), openPic);
GUI.DrawTexture(Rect(570,80,500,500), Class.type);
GUI.DrawTexture(Rect (490,50,500,500),Class.Level);
GUILayout.BeginArea(Rect(1100,620,1200,800));
AvaibleAbilities = GUILayout.BeginScrollView(AvaibleAbilities, GUILayout.Width(70), GUILayout.Height(180));
GUILayout.BeginVertical();
GUILayout.Button(Class.actions.icon);
GUILayout.EndVertical();
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
function Start (){
WaitForSeconds(1);
Class = Self.GetComponent("HUD").ClassType;
}
Then I have the Spell class :
class Spell{
var name : String;
var type = "action";
var icon : Texture2D;
static var description : String;
var Damage : int;
var animation : AnimationClip;
var Projectile : Transform;
var Cooldown : int;
var Level : int;
// The generic use function for the action
function use(){
Debug.Log(description); // Do stuff
}
}
So is there any methods I can use to do this?
Seems like a simple for loop using the index on the array would work if you use Actions*.icon for the GUIContent. Im on my phone but if you want a code example I wouldnt mind helping*
– Josh707