Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Sacar nombre de textura

Iniciado por cirepa, Febrero 11, 2016, 09:45:14 PM

Tema anterior - Siguiente tema
Febrero 11, 2016, 09:45:14 PM Ultima modificación: Febrero 14, 2016, 07:54:33 PM por cirepa
Hola Amigos:Alguien sabe como sacar el nombre de una textura asignada a un material en un GameObject?Estoy probando esto pero me da error al imprimir esto ocurriría al tocar el objeto.
   void Update () {
   if(Input.GetMouseButtonDown(0) ){
      Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
      RaycastHit hit;
      if (Physics.Raycast(ray, out hit, 100))
         if(hit.transform.GetComponent<MemoryCard>() != null){
         Texture old = hit.transform.GetComponent<Renderer>().material.GetTexture("_MainTex");
         Debug.Log(old.name);
 // 30
            hit.transform.GetComponent<MemoryCard>().Show();
         //print(hit.transform.GetComponent<Renderer>().materials[0].GetTexture(name));
      //   Texture testura = hit.transform.gameObject.GetComponent<Renderer>().material.GetTexture("_MainTex");

            
         }
   }
}
Gracias.Un saludo


Febrero 14, 2016, 07:56:15 PM #2 Ultima modificación: Febrero 14, 2016, 08:01:29 PM por cirepa
Ya esta solucionado , tenia dos materiales y el 0 no tenia textura
Texture old = hit.transform.GetComponent<Renderer>().materials[1].GetTexture("_MainTex");
         Debug.Log(old.name);
De esta forma si que imprime el nombre

Etiquetas: