- Home /
Question by
KenE · Oct 20, 2014 at 09:25 AM ·
filesgame objectgame-objectput
Put texture on game object from file.
I'm making it so that a program will be able to load a image file and put that texture onto an object. Perhaps I'm going about it the wrong way. Here is my current relevant code for it. Take Note I am also accessing the object from another object script. Thanks for any help.
public GameObject frontTexture;
.....
frontTexture = GameObject.Find ("Front");
.....
if (GUILayout.Button ("Input to card ")) {
string file = EditorUtility.OpenFilePanel ("Hello", "", "png");
if(file.Length != 0)
{
WWW www = new WWW("file:///" + file);
www.LoadImageIntoTexture(frontTexture.renderer.material.mainTexture);
}
Comment
Best Answer
Answer by KenE · Nov 17, 2014 at 06:27 AM
So through some work I found the answer
public Texture2D frontTexture;
public GameObject frontObject = GameObject.Find("Front");
string file = EditorUtility.OpenFilePanel ("Hello", "", "png");
if (file.Length != 0)
{
WWW www = new WWW ("file:///" + file);
www.LoadImageIntoTexture (frontTexture);
}
I was trying to load the texture directly into the gameobject texture. You have to apply it to a texture first then the gameobject later.
Your answer
Follow this Question
Related Questions
Smooth enter orbit 2 Answers
Multiple files for animation - play issue 0 Answers
String.Split With Backslash 2 Answers
3rd party files in unity asset? 0 Answers
Show files extensions in project window 2 Answers