- Home /
How to create a texture from an image and assign it to a skykbox
This is what I found but no answer.
http://answers.unity3d.com/questions/348982/resourcesloadpathname-as-texture-null-reference.html
I used exactly the same method.
skyBox = mainCamera.gameObject.AddComponent<Skybox>();
Texture texture = Resources.Load("mario") as Texture;
if(texture != null){
Debug.Log(texture.width);
Debug.Log(texture.height);
skyBox.material.mainTexture = texture;
}
This is my code. The output is 1024(width) and 512(height), so the texture is not a null. But when assigned to skybox, NullReferenceException throws.
Please help. Thanks.
Why not just create a separate image outside the editor and assign it?
http://docs.unity3d.com/Documentation/$$anonymous$$anual/HOWTO-UseSkybox.html
Answer by Julien-Lynge · Feb 17, 2013 at 07:32 PM
This line is meaningless to Unity:
mainCamera.gameObject.AddComponent();
Please see the documentation for AddComponent.
Also, as LightSource said, there are other ways to assign an image if you're not trying to do it at runtime. What exactly are you trying to do?
Thanks. But I need to assign the background at runtime.
Okay. What could be possible, is to have the image you want record its own texture. Or if you want to get really advanced, you could have a extra camera take a picture. What exactly are you trying to do.
Your answer
Follow this Question
Related Questions
Texture compression Skybox seams 1 Answer
Dynamically changing skybox texture 0 Answers
Android skybox not visible in emulator 0 Answers
Is there any way to change skybox size? 3 Answers