Hey Guys,
Thanks for the help in advance. I’m trying to make a health bar using a cutout material, but that’s beside the point. For whatever reason, I can’t seem to be able to simply draw a texture using “Graphics.DrawTexture” and assigning a texture through the inspector. Here’s the code (javascript):
#pragma strict
var x : int;
var y : int;
var width : int;
var height : int;
var box : Rect = new Rect(x, y, width, height);
var tex : Texture2D;
var mat : Material;
function OnGUI(){
if(Event.current.type.Equals(EventType.Repaint)){
Graphics.DrawTexture(box, tex);
}
}
I’ve tried using a material, omitting the material, changing the texture I use to something that I know renders, etc… I’ve been troubleshooting for hours and can’t seem to find the problem. Here’s the error I’m getting in the console:
DrawGUITexture: texture is null
UnityEngine.Graphics:DrawTexture(Rect, Texture)
RenderHealthAndOtherGUI:OnGUI() (at Assets/RenderHealthAndOtherGUI.js:15)
Yes, I’ve made sure to assign the texture in the inspector. The object this is attached to in an instantiated clone, but I don’t think that should have an effect, right?
The documentation pages aren’t clearing anything up for me either. Any help is very much appreciated. I don’t know why I’m stumped on such a simple issue. Thanks!