8
\$\begingroup\$

I want to have a plane that shows an animated Gif as it's texture, so essentially it will be a movie. Can I apply an animated Gif as a texture? If so, does it apply like a normal texture? Note: I know about Movie Textures, but don't want to use them

\$\endgroup\$
3
  • 4
    \$\begingroup\$ the GIF file format was subject to patents for really long time and the graphics industry has not a really good support for this format since it's not a really good format for this purpose ( animation ) and there are other ways to do almost the same thing with some simple sprites putted in series in a single image and used in sequence when you want to animate your character. \$\endgroup\$ Commented Aug 26, 2012 at 15:24
  • \$\begingroup\$ @user827992 So I would do something like described here where I am constantly changing the texture? \$\endgroup\$ Commented Aug 26, 2012 at 15:25
  • 1
    \$\begingroup\$ that's more or less what a sprite is used for, answers.unity3d.com/questions/45530/animated-sprites.html or google.com/#q=unity+3d+animated+sprites or forum.unity3d.com/threads/…! \$\endgroup\$ Commented Aug 26, 2012 at 15:30

2 Answers 2

8
\$\begingroup\$

Short answer is no. You will need to convert the GIF to an atlased texture (a single 2D image that has all the GIF frames in it) and then cycle the UV coordinates on a textured quad to change which frame is currently visible. This is not particularly hard to do, and there are existing sprite animation packages for Unity that can do most of it for you (you'll likely have to create the atlas yourself, or at least split the GIF into separate PNG images for each frame to use an existing atlas creator).

\$\endgroup\$
3
  • \$\begingroup\$ Thanks, and what object would I use to do this? \$\endgroup\$ Commented Aug 26, 2012 at 16:40
  • \$\begingroup\$ You can animate the UVs of a mesh component manually. There are packages in the Asset Store that do all of this for you, but I don't have experience with any of them so I can't make a recommendation as to which to use. \$\endgroup\$ Commented Aug 26, 2012 at 16:44
  • \$\begingroup\$ I have no personal experience with it, but I hear ShoeBox is pretty slick. It supports converting animated GIFs to Unity texture atlases. \$\endgroup\$ Commented Aug 27, 2012 at 4:33
0
\$\begingroup\$

I made this script. Just attach it to the gameobject, for example a plane and then just fill the frames array with all the frames of the gif in the inspector.

public class AnimGif : MonoBehaviour { [SerializeField] private Texture2D[] frames; [SerializeField] private float fps = 10.0f; private Material mat; void Start () { mat = GetComponent<Renderer> ().material; } void Update () { int index = (int)(Time.time * fps); index = index % frames.Length; mat.mainTexture = frames[index]; // usar en planeObjects //GetComponent<RawImage> ().texture = frames [index]; } } 
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.