0

Estou fazendo uma nova aplicação e preciso carregar foto de um diretório específico no computador neste caso c:\\Biosearchassets para uma gui texture no unity3d eu consegui encontrar um exemplo mas ele usa a texture2D e eu quero carregar em 3D gui texture tentei mudar o código mas obtenho este erro

Assets/LoadImage.cs(42,29): error CS1503: Argument '#1' cannot convert 'UnityEngine.Texture' expression to type 'UnityEngine.Texture2D'

O meu código é

using UnityEngine;
using System.Collections;

public class LoadImage : MonoBehaviour {
GameObject[] gameObj;
Texture[] textList;

string[] files;
string pathPreFix; 

// Use this for initialization
void Start () {
    //Change this to change pictures folder
    string path =    @"C:\Biosearchassets\";

    pathPreFix = @"file://";

    files = System.IO.Directory.GetFiles(path, "*.jpg");

    gameObj= GameObject.FindGameObjectsWithTag("Pics");

    StartCoroutine(LoadImages());
}


void Update () {

}

private IEnumerator LoadImages(){
    //load all images in default folder as textures and apply dynamically to plane game objects.
    //6 pictures per page
    textList = new Texture[files.Length];

    int dummy = 0;
    foreach(string tstring in files){

        string pathTemp = pathPreFix + tstring;
        WWW www = new WWW(pathTemp);
        yield return www;
        Texture texTmp = new Texture(1024, 1024, TextureFormat.DXT1, false);  
        www.LoadImageIntoTexture(texTmp);

        textList[dummy] = texTmp;

        gameObj[dummy].GetComponent<Renderer>().material.SetTexture("_MainTex", texTmp);
        dummy++;
    }

}
}

1 Resposta 1

0

De facto depois de muito procurar por uma solução decidi de alterar o meu codigo e fazer de novo, codigo funcionando as maravilhas:

Este e o Codigo Final

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Linq;

public class LoadImage : MonoBehaviour 
{
private Object[] textures;
public GameObject go;
public static string stringto;


void Start()
{
    textures = Resources.LoadAll("Textures", typeof(Texture2D));

    //foreach (var t in textures)
    //{
    //  Debug.Log(t.name);
        //stringto +=t.name;

    //}


}

void OnGUI()
{
    if (GUI.Button(new Rect(10, 70, 150, 30), "Change texture"))
    {
        foreach (var t in textures)
        {
            Debug.Log(t.name);
            stringto +=t.name;

        }
        // change texture on cube
        Texture2D texture = (Texture2D)textures[Random.Range(0, textures.Length)];
        go.GetComponent<Renderer>().material.mainTexture = texture;


        GameObject.Find("GUIText").GetComponent<TextMesh>().text = texture.name;




        //GUI.Label (Rect (10, 10, 100, 20), stringto);
        //stringto = GUI.TextField(new Rect(10, 10, 200, 20), stringto, 25);
    }
}
}

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .