I'm getting started with Unity, but having trouble with the most basic of operations - getting an image to appear on the screen.
I've tried researching this, but almost all the tutorials / info on Unity are about more advanced usage and don't cover the basics. There's very little info out there on basic image loading and drawing.
My project has one object, with this script attached:
public class Boxland_Main : MonoBehaviour
{
Texture2D test_sprite;
void Start ()
{
print ("STUFF"); // this works
test_sprite = (Texture2D) Resources.Load ("richard_green.png");
}
void Update ()
{
GUI.DrawTexture (new Rect(0, 0, 50, 50), test_sprite); // this doesn't work
}
}
My image file is in the Resources directory, but all I ever get is a powder blue screen.
EDIT:
For clarity, I'd be interested in any solution that just gets an image up on the screen. I feel I'm getting close to going back to XNA or GameMaker.
UPDATE:
Here's what I've got now (still with no sprite being drawn):
public class Boxland_Main : MonoBehaviour
{
public Texture2D test_sprite;
void Start ()
{
test_sprite = (Texture2D) Resources.Load ("richard_green");
}
void OnGui ()
{
if (test_sprite) GUI.DrawTexture (new Rect (0, 0, 50, 50), test_sprite);
}
}
UPDATE:
I found that if I drag an image directly from the asset window onto the scene window in the Unity UI, it adds the sprite to the view and the sprite shows up on compile. However, it's rendering blurry and pixelated, and there doesn't seem to be any way to specify a particular frame on the sprite sheet.
UPDATE:
I came across some material while researching that may point to a partial answer:
Unity 4.3 - 2D, how to assign programmatically sprites to an object http://docs.unity3d.com/ScriptReference/Resources.Load.html
This seems to cover loading an image, but never goes into explaining how to draw the image.