- Home /
Gui.DrawTexture Working in Scene Mode, but not build or full game scene
Hello, I just started using Unity a couple of days ago, and I think I'm starting to get the hang of it, but not really.
Anyways, I've created this script to fade my scenes in and out, and it works when I preview the scene, but not when I build the game, or when I preview the game as a whole in the editor.
Here's my C# script:
//this is our boolean to control when we want to fade out
public static bool nextScene;
public float duration = 0.5f;
//our actual texture
public Texture image;
//create our GUI so that it will always draw on top
void OnGUI () {
//draw above our other guis
GUI.depth = 0;
fadeIn ();
//now create our gui texture
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height),
image);
}
// Use this for initialization
void Start ()
{
nextScene = false;
}
// Update is called once per frame
void Update ()
{
if (nextScene) {
fadeOut ();
}
}
//function for fading in
void fadeIn(){
GUI.color = Color.Lerp(Color.black, Color.clear, Time.time * duration);
}
//function for fading out
void fadeOut(){
GUI.color = Color.Lerp(Color.clear, Color.black, Time.time * duration);
}
any help is appreciated, as I've been trying to figure this out for a while. Thank you!
Try load image in scrirpt. $$anonymous$$ove image to Assets/Resources folder and then add this to Start function:
image = Resources.Load("image_name.jpg",typeof(Texture)) as Texture;
Answer by LSPressWorks · Aug 02, 2014 at 08:53 AM
I had the same issue, try setting your render path in the build options to vertex lit and see if that helps. Worked for me even after changing it back to forward.
Answer by MvNimwegen · Sep 10, 2021 at 12:30 PM
Set your methods to public, or add an obfuscation attribute. Upon building, these methods names get obfuscated. Since Unity finds these methods through Reflection, it does not run those methods anymore.
Your answer
Follow this Question
Related Questions
How to gradient-wise fill a bitmap programmatically 1 Answer
Equivelant of GUI.DrawSprite() ? 0 Answers
How To Print Text Random 2 Answers
Way to have a pause and play texture in same GUI texture? 0 Answers