Search Unity

[SOLVED]GUITexture rotation

Discussion in 'Immediate Mode GUI (IMGUI)' started by flyber, Sep 14, 2009.

  1. flyber

    flyber

    Joined:
    Sep 14, 2009
    Posts:
    12
    Hi, all

    I creating main menu for our game and I need rotation some elements, but rotation for GUITexture doesn't work.

    if...
    Code (csharp):
    1. void Update () {
    2.  transform.Rotate(0.0f, 0.0f, 10.0f);
    3. }
    We have not any movement.

    if...
    Code (csharp):
    1. void Update () {
    2.  transform.Translate(0.005f, 0.0f, 0.0f);
    3.  transform.Rotate(0.0f, 0.0f, 10.0f);
    4. }
    We have some progress, but not we want exactly.

    Thank you.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Correct, GUITextures do not support rotation.

    --Eric
     
  3. flyber

    flyber

    Joined:
    Sep 14, 2009
    Posts:
    12
    What can I use instead of GUITextures?
     
  4. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    You can use GUIUtility.RotateAroundPivot to rotate a GUI.Label.
     
  5. flyber

    flyber

    Joined:
    Sep 14, 2009
    Posts:
    12
    I need rotate a sprite...
     
  6. flyber

    flyber

    Joined:
    Sep 14, 2009
    Posts:
    12
    Code (csharp):
    1. void OnGUI ()
    2. {
    3.   GUIUtility.RotateAroundPivot (10.0f, new Vector2(240.0f, 160.0f));
    4.   GUI.DrawTexture(new Rect(0.0f, 0.0f, 480.0f, 320.0f), BGTexture, ScaleMode.StretchToFill, true, 0);
    5. }
    I has used that code and it is working.

    Thank all. :)
     
  7. spaceMan-2.5

    spaceMan-2.5

    Joined:
    Oct 21, 2009
    Posts:
    710
    hmm, is there a special reason that GuiTexture can´t to rotate?.... looks like a bit weird...
     
  8. spaceMan-2.5

    spaceMan-2.5

    Joined:
    Oct 21, 2009
    Posts:
    710
    Not sure but maybe there is a easier way to do it...

    not to using GUITexture, just using a plane, apply a texture to it, add a camera and set it to orto, and render only the object you want to rotate....
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    using guitexture for sprites is a totally horrible idea anyway.

    It won't batch, you can't do uv animations etc, many good reasons to not even consider it.

    Use a mesh based system for sprites and alike, if you don't want to start at 0, use SpriteManager1, if you want a cool editor, animation etc, then invest into Sprite Manager 2 :)
     
  10. supershwa

    supershwa

    Joined:
    Feb 10, 2013
    Posts:
    12
    This essentially makes my GUITexture rotate properly. The solution is more complex than a .rotation property for a reason. Make sure to define "myRotatingTexture" using your own methods (Resources.Load or WWW or whatever.) Works great with scanner/radar sweeps, eyeballs, clock hands, map compass, "follow mouse cursor", etc.

    Code (csharp):
    1.  
    2. private static int rotationAngle = 0;
    3.      
    4. void onGUI() {
    5.  
    6.     //do other GUI stuff here - it will not be rotated, example:
    7.     //GUI.Label(new Rect(0,0,Screen.width,100), "Hello World");
    8.  
    9.     //rotating 256x256 GUITexture in a GUI Group:
    10.     GUI.BeginGroup(new Rect(0,0,Screen.width,Screen.height));
    11.     rotationAngle += 5;
    12.     GUIUtility.RotateAroundPivot(rotationAngle , new Vector2(Screen.width/2, Screen.height/2));
    13.     GUI.DrawTexture(new Rect(Screen.width/2 - 128, Screen.height/2 - 128, 256, 256), myRotatingTexture);
    14.     GUI.EndGroup();
    15. }
    16.  
     
    Last edited: Aug 23, 2013
  11. Laundro

    Laundro

    Joined:
    Oct 5, 2013
    Posts:
    8
  12. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    @Dreamora GUITexture have an advantage against Canvas and any other newer GUI based system..
    the advantage is that all GUITextures will match any sort of resolution and aspect ration, even if you anímate it with Transform.. i tried a lot with canvas and ngui for this with no result... the animated (transform transition) sprite gets out of bounds when aspect ratio switches...

    This 1:50 (time) video explains it... may i´m bad?

     
    Last edited: Jan 28, 2016