- Home /
Animate a GuiTexture to make a spinning object
I've been looking around for this and most of the other answers didn't help or were wrong somehow.
I've basically copied what this JavaScript does (but re-wrote it in c#). Unfortunately this script is for controlling materials on a 3d object and not a Gui Texture.
So what I've got so far, is created the strip of images of the object spinning on each frame. Set the texture on the GuiTexture, and played around with the width and right border values to get it to show just one frame.
The problem I'm having is being able to set the offset of this texture, but I can't do it like in the link. I also can't seem to edit the border values through script so I won't be able to change width and border values to do it.
By the looks of it, I think I'm going to have to have to resort to this instead, since it seems like the only possible way for it to work. Yay for having to recreate every single frame into it's own image and using an array of Texture2D.
Any reason for using GUITexture? It doesn't seem appropriate, given the limitations.
I'm not exactly sure how else to go about this, should I have used a 3d object ins$$anonymous$$d and sat him in front of the camera? It seems a bit dodgy, or is that still a good way.
Answer by Rabwin · May 14, 2011 at 07:08 AM
Can't change tiling or the scroll of a gui texture so my only solution was to either make a plane and set that to camera.nearplane (or wahtever it's called) or scroll through different textures using a similar code for frames per second. This second option is what I chose.
I made a separate image for each frame and set them into cache using numbered names for each image during the awake function.
using this in ongui, I could scroll through them at a good constant speed and create my animated gui.
// Calculate index curFrame += Time.deltaTime * frameScrollSpeed;
// repeat when exhausting all frames int index = Mathf.FloorToInt(curFrame) % guiPic.Length;
// change frame according to index GUI.DrawTexture(new Rect(10, 8, 30, 28), guiPic[index]);
frameScrollSpeed is a float of the speed I wanted.
guiPic is an array of type Texture2D.
Answer by burgunfaust · May 08, 2011 at 03:11 PM
GUITexture is very limited. But it's limitations make it stronger for what it does do well, making GUIs. What you are trying to do will not work, to best of my knowledge with guitexture, but you should be a ble to do it with a regular 3D object, even as part of a GUI.
EDIT: Try looking at this, specifically the character visual setup. I uses a sprite sheet for a topdown. http://www.rebelplanetcreations.com/downloads/Other/Tutorials/HowToMakeAGameInUnity3D.pdf
What do you mean, a 3d object as part of a GUI? Is that like creating an object and setting it as a child of the camera while it's sitting in front of it.
A GUI is just a 2d menu in 2d space (the screen). Just do what you are trying to do on a 3d object. Then go from there on how to proceed with what you are trying to do. Is this for a game menu of some sort or what?
It's part of a user interface while the player is in-game. To be more specific on what I'm trying to do, theres a spinning image of a gem I have, and next to it is a gui text that updates using a score.
I have the tiled strip of the gem's frames setup, I just can't manage to do this.
Unfortunately this type of scrolling of a texture only works on objects and not the gui texture like I wanted.
I had by now already found another solution, and that was unfortunately to create an image for each frame and then scroll through that cache of textures.
Thanks for your support though, I couldn't have come up with my solution without talking to you.