Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by IronMike · Dec 07, 2010 at 02:05 AM · drawtexture

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?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IronMike · Dec 07, 2010 at 07:54 AM 0
Share

I just read the Graphics.DrawTexture is for Unity Pro ONLY

avatar image IronMike · Dec 07, 2010 at 08:32 AM 0
Share

After lots and lots and lots of searching, it appears that GUI.(etc) can only be used in OnGUI unless you do the class solution below. However, I don't necessarily have to use GUI.DrawTexture. I just want to place an image (texture) at a particular point in front of my GUI.Texture that acts as a full screen background. Once I place the image I want to move and rotate it to another point. Then I want to flip it to reveal a new image (texture) on the other side, and lastly move it to yet another point. How do I place an image infront of my background?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Justin Warner · Dec 07, 2010 at 02:18 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image IronMike · Dec 07, 2010 at 04:12 AM 0
Share

Thanks for the links. I have seen those but I'm still looking for an easy solution. The class seems good but maybe there is a better way.

It seems to me that I should be able to put a Texture in my scene dynamically without having to do a lot of coding.

If I can call an audio when I click a GUI Button, why not add a graphic in one line too.

What about Graphics.DrawTexture? I've put that in and I get the same result.

avatar image
0

Answer by denewbie · Dec 07, 2010 at 05:38 PM

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:

  • 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.

  • 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.

  • 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(){

    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.

    Comment
    Add comment · Show 3 · Share
    10 |3000 characters needed characters left characters exceeded
    ▼
    • Viewable by all users
    • Viewable by moderators
    • Viewable by moderators and the original poster
    • Advanced visibility
    Viewable by all users
    avatar image IronMike · Dec 08, 2010 at 10:34 PM 0
    Share

    This sort of worked. It does put the texture on the screen but now it plays the audio in a never ending loop and it updates the text infinitely. I suppose I can add some more code to prevent all this but I still need to move the texture and spin it, then flip it and move it again.

    Adding a plane with a texture on it still seems like the best way. Thanks for the response.

    avatar image denewbie · Dec 09, 2010 at 06:08 PM 0
    Share

    Hi. I;ve edited my answer to suit your query. Hope it helps. The idea is there. IF there're any bugs you can just send me a comment of something. All the best to you. =)

    avatar image mviuk · Jun 27, 2012 at 09:18 AM 0
    Share

    Re 1: GUI can both rotate and flip, you just need to supply a transformation matrix to GUI.matrix, see http://unity3d.com/support/documentation/ScriptReference/GUI-matrix.html and http://forum.unity3d.com/threads/6954-video-intro?p=53105#post53105

    Re 2: A plane, specifically a quad, is the way to go, admittedly the default Unity plane is 200 tris, so use a 2 tri plane ins$$anonymous$$d, you can either generate this like http://www.unifycommunity.com/wiki/index.php?title=CreatePlane or store a 3D model like http://code.google.com/p/ogldev/source/browse/trunk/tutorial30/quad.obj?spec=svn52&r=52

    Your answer

    Hint: You can notify a user about this post by typing @username

    Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

    Follow this Question

    Answers Answers and Comments

    No one has followed this question yet.

    Related Questions

    How to make foot to leave a print on snow? 1 Answer

    GUI.DrawTexture shows in Unity but not in Build 1 Answer

    GUITexture makes my image to low quality 1 Answer

    How can I trace Alphabet 0 Answers

    Blinking loop of images? Half-done... 1 Answer


    Enterprise
    Social Q&A

    Social
    Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

    Footer

    • Purchase
      • Products
      • Subscription
      • Asset Store
      • Unity Gear
      • Resellers
    • Education
      • Students
      • Educators
      • Certification
      • Learn
      • Center of Excellence
    • Download
      • Unity
      • Beta Program
    • Unity Labs
      • Labs
      • Publications
    • Resources
      • Learn platform
      • Community
      • Documentation
      • Unity QA
      • FAQ
      • Services Status
      • Connect
    • About Unity
      • About Us
      • Blog
      • Events
      • Careers
      • Contact
      • Press
      • Partners
      • Affiliates
      • Security
    Copyright © 2020 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell My Personal Information
    • Cookies Settings
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Explore
    • Topics
    • Questions
    • Users
    • Badges