- Home /
if texture used from class it does not show in game, advice needed?
here is the test class i made:
class Button extends Object{
//VARIABLES
var x:int;
var y:int;
var w:int;
var h:int;
var texture:Texture2D;
//CONSTRUCTOR
function Button(){
x=10;
y=10;
w=30;
h=30;
}
function Show(){
if(GUI.Button(Rect(x,y,w,h),texture)){
Debug.Log("Button Pressed!");
}
}
}
slot for texture appears when i create the object in other script. here is how i did it:
var TestButton : Button;
then in the OnGUI function i just type this:
TestButton.Show();
the button shows and it works but texture is not there but i put it in the slot from the inspector, what i am doing wrong?
here is the screenshot:
Answer by Mike 3 · Nov 09, 2010 at 08:10 PM
The default references doesn't work like that - it lets you set what the variables will be set to when you drag that script onto a gameobject
Since your class isn't a monobehaviour, the default references is completely useless to you for it
Try looking into Resources.Load instead, it'll load from the /Assets/Resources folder at runtime
Your answer
Follow this Question
Related Questions
Create a drag and drop element in the custom editor for textures. 1 Answer
Change a Class in the inspector 1 Answer
class attribute inspector 0 Answers
Assigning UV Map to model at runtime 0 Answers