With the following code:
public Texture2D Tick;
public GUITexture Test;
void Start () {
Tick = (Texture2D) GameObject.Find("Tick").guiTexture.texture;
print(Tick);
Test = new GUITexture();
Test.texture = Tick;
}
I get the following output:
tick_mark (UnityEngine.Texture2D)
NullReferenceException
HUD.Start () (at Assets/Scripts/Player/HUD.cs:46)
Line 46 points to: “Test.texture = Tick;”
Obviously, as shown by the print statement, Tick definitely holds a valid Texture2D object.
Casting it explicitly using (Texture) or (Texture2D) has no effect, as does using Test.guiTexture.texture , or a combination of them.
I am very much stumped