GUI.DrawTexture not working

This must be the easiest question in this forum.

I have a GUI.DrawTexture that works perfectly in the OnGUI function but when I move it to a different function and then call that function from a GUI.Button, it doesn't display.

I know the function is being called because I use audio.PlayOneShot in that function and the sound plays.

Any ideas?

It might be different resolutions... Try it with the button in the upper left corner...

http://forum.unity3d.com/threads/37439-solved-GUI-from-outside-OnGUI(-)

Also, that, but I thought you could without it being on OnGui, maybe check out:

http://www.unifycommunity.com/wiki/index.php?title=PauseMenu

They do function calls in gui.

I'm guessing that it probably because it did display. Rather, it only displayed once and that was when you called that so called function. If you want it do display from another function upon a mouse click try the method below.

// I'm using C# a lot these days so just bare with it. The ideas is that we get the right concept.

    // We're gonna make use of a boolean to control the printing of the texture.

     bool isPrinting = false;

    // Then we have our OnGUI as normal

    void OnGUI(){

       if ( GUI.Button( new Rect(0,0,50,50), "Toggle") )
       {
            if (isPrinting)
                  isPrinting = false;
           else
                  isPrinting = true;

           if (isPrinting)
           {
                // Put your audio script here. 
           }
       }

       if (isPrinting)
           printTexture();
    }

    void printTexture(){

       GUI.drawTexture( new Rect(0, 50, 50,50), myTexture );

    }

For 3D plane:

  1. First off, GUI in Unity can't rotate or flip. the best it can do is to move and that requires quite some computing so you are right to go for 3D animation.

  2. Secondly, I don't recommend using a plane. Rather, I'll recommend using a cube instead because comparatively, its much lighter in terms of polygon count.

  3. Here's some script you can start off with to what you might want to do.

    // First lets declare some configurable parameters

    public float rotationCount = 1; public float rotationCount2 = 1;

    public float moveSpeed = 1; public float rotateLapse =0; public float rotateLapse2 =0;

    public Texture2D myTexture; public GameObject myPlaneObject;

    public float moveTime = 2; private float timeLapse = 0;

    public float moveTime2 = 2; private float timeLapse2 = 0;

    bool isAnimating = false;

        void OnGUI(){
    
    <pre>`   if ( GUI.Button( new Rect(0,0,50,50), "Toggle") )
       {
            if (isAnimating )
                  isAnimating = false;
           else
                  isAnimating = true;
    
           if (isAnimating )
           {
                // Reset all variable values
               rotateLapse  =0;
               rotateLapse2  =0;
    
               timeLapse = 0;
               timeLapse2 = 0;
    
                // Put your audio script here.
    
                // Render and unrender your object accordingly
                myPlaneObject.renderer.enabled = isAnimating;  // Please make sure your attached object has a renderer.
           }
       }
    }
    
    

    `

    void Update(){ if (isAnimating ) AnimateObject(); }

    void AnimateObject(){ // Put your audio script here.

     // Lets do a move first. You can choose to translate left, right, up or  up *-1 (down), forward or a combination.
    if ( timeLapse < moveTime)
    {
           myPlaneObject.transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
           timeLapse += Time.deltaTime;
    }
    
    // Now lets rotate the object
    else if ( rotateLapse  < rotationCount)
    {
           myPlaneObject.transform.Rotate(Vector3.left * Time.deltaTime);
           rotateLapse += Time.deltaTime;
    }
    
    // Now lets flip the object by using the Rotate again again
    else if ( rotateLapse2  < rotationCount2)
    {
           myPlaneObject.transform.Rotate(Vector3.forward * Time.deltaTime);
           rotateLapse2 += Time.deltaTime;
    }    
    
     // Finally, Lets do a move again. 
    else if ( timeLapse2 < moveTime2)
    {
           myPlaneObject.transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
           timeLapse2 += Time.deltaTime;
    }
    else
    {
        isAnimating = false;
    }
    
    

    }

I haven't tested it but the idea is there.