I’m trying to draw a GUI with my own textures. I have a GUIObjectTemplate class in one script, and GUITab class in another script (inheriting from GUIObjectTemplate). GUITabs are instantiated and controlled in a script attached to a GameObject.
What I’m trying to do is assign Texture2D’s to the “texture” and “texture_alt” variables. I do so by going to the GUITab script in the Inspector and dragging the textures into Default References. It doesn’t seem to work though, they are Null at runtime and the program crashes at the GUI.DrawTexture() call : (
Below is the simplified code…
using UnityEngine;
using System.Collections;
public class GUIObjectTemplate : ScriptableObject {
public Texture2D texture;
public Rect area;
public GUIObjectTemplate() {
//Constructor
}
// Use this for initialization
public virtual void Start () {
}
// Update is called once per frame
public virtual void Update () {
}
}
using UnityEngine;
using System.Collections;
public class GUITab : GUIObjectTemplate {
public Texture2D texture_alt;
public bool selected = false;
//Constructor
public GUITab(Rect _area) {
area = _area;
Debug.Log(area); //OK!
Debug.Log(texture_alt); //Returns Null :/
}
public void Draw() {
Debug.Log(area); //OK!
Debug.Log(texture_alt); //Null
GUI.DrawTexture(area, texture_alt);
}
}