- Home /
GUITexture disappears in build
Hey there,
I loaded a GUITexture on the scene and if i leave it there and i build the proyect, everything is fine, the GUITexture appears on the screen, but when i load a C# script to the GUITexture, and then i build the proyect, the Guitexture is gone.... However the script works just fine before building the proyect, its an animation, the script replaces the GUITexture image for another one.... here is the script:
using UnityEngine; using System.Collections;
public class fred : MonoBehaviour {
string fred1 = "Assets/Materials/textures/fred.png";
string fred2 = "Assets/Materials/textures/fred2.png";
// Use this for initialization
IEnumerator Start () {
int c=0;
Texture fredim = Resources.LoadAssetAtPath(fred1,typeof(Texture)) as Texture;
Texture fredimm = Resources.LoadAssetAtPath(fred2,typeof(Texture)) as Texture;
guiTexture.texture = fredimm;
while(true){
if(c==0){
guiTexture.texture = fredim;
c=1;
yield return new WaitForSeconds(0.5f);
} else {
guiTexture.texture = fredimm;
c=0;
yield return new WaitForSeconds(0.5f);
}
yield return new WaitForSeconds(.05f);
}
}
// Update is called once per frame
void Update () {
}
}
Answer by Positive7 · Jul 19, 2015 at 10:07 AM
LoadAssetAtPath works in the Editor only. And move Materials folder under Assets/Resources/
using UnityEngine;
using System.Collections;
public class fred : MonoBehaviour {
string fred1 = "Materials/Textures/fred";
string fred2 = "Materials/Textures/fred2";
IEnumerator Start () {
int c=0;
Texture fredim = Resources.Load (fred1) as Texture;
Texture fredimm = Resources.Load (fred2) as Texture;
guiTexture = fredim;
while(true){
if(c==0){
guiTexture = fredim;
c=1;
yield return new WaitForSeconds(0.5f);
} else {
guiTexture = fredimm;
c=0;
yield return new WaitForSeconds(0.5f);
}
yield return new WaitForSeconds(.05f);
}
}
}
Thank you very much, you made my day, im going to try this later...
Your answer
![](https://koobas.hobune.stream/wayback/20220611231855im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GUI not working in Build? 1 Answer
Reduce Draw call for Multiple GUI Textures with same Texture 1 Answer
Distribute terrain in zones 3 Answers
Build is changing GUI positions 1 Answer
Sphere disappear after build 0 Answers