Hi folks. I'm mostly clueless when it comes to programming outside of the basics. I am using unity free and wanted to try gif's for water effects but they do not play I found this script online but can't get it to work I think I must be missing some steps maybe. Here's the script and after i will say what i have tried . Code (CSharp): C# - AnimatedGifDrawer.cs using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using UnityEngine; public class AnimatedGifDrawer : MonoBehaviour { public string loadingGifPath; public float speed = 1; public Vector2 drawPosition; List<Texture2D> gifFrames = new List<Texture2D>(); void Awake() { var gifImage = Image.FromFile(loadingGifPath); var dimension = new FrameDimension(gifImage.FrameDimensionsList[0]); int frameCount = gifImage.GetFrameCount(dimension); for (int i = 0; i < frameCount; i++) { gifImage.SelectActiveFrame(dimension, i); var frame = new Bitmap(gifImage.Width, gifImage.Height); System.Drawing.Graphics.FromImage(frame).DrawImage(gifImage, Point.Empty); var frameTexture = new Texture2D(frame.Width, frame.Height); for (int x = 0; x < frame.Width; x++) for (int y = 0; y < frame.Height; y++) { System.Drawing.Color sourceColor = frame.GetPixel(x, y); frameTexture.SetPixel(frame.Width - 1 - x, y, new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A)); // for some reason, x is flipped } frameTexture.Apply(); gifFrames.Add(frameTexture); } } void OnGUI() { GUI.DrawTexture(new Rect(drawPosition.x, drawPosition.y, gifFrames[0].width, gifFrames[0].height), gifFrames[(int)(Time.frameCount * speed) % gifFrames.Count]); } } These were the instructions and what i tried in // 1) Copy the "System.Drawing.dll" file in the "C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0" folder into your "Assets" folder..//DONE 2) Create a new script named "AnimatedGifDrawer", with the contents shown below.//DONE 3) Attach this script to any object in your scene.//DONE attached to empty game object 4) Change the "loadingGifPath" field of the script, (in the Inspector view), to the path of your Gif file. (this can be relative, from the root project folder (i.e. the parent of the "Assets" folder), or absolute) // I have dowloaded a gif called water then imported it to unity just into assets. I have saved unity project "test" to my c drive. so the water gif is in Asset "test" on the c drive. . The error i get FileNotFoundException: water System.Drawing.Image.FromFile (System.String filename, Boolean useEmbeddedColorManagement) System.Drawing.Image.FromFile (System.String filename) AnimatedGifDrawer.Awake () (at Assets/AnimatedGifDrawer.cs:15) I tried just putting the name of the gif water in the field tried \Assets\water c:\test\Assets\water Do i need to do something to the gif first am I using a wrong path? Thx for any help
You need to have full filename for the file but rather that doing that I suggest you change the whole thing cause reasons like: gif format is unsupported in unity, adding the support via copying version specific dll files is not practical and does not work well on all platforms, etc. export all the frames out of the gif with some tool and animate them as normal sprite animation
There's few plugins in asset store to create gif anims, like: https://www.assetstore.unity3d.com/en/#!/content/32092
Yea someone pointed me to a script that worked great . Can't sem to find it now. But i saw a tutorial on how to use water pro features in basic so switched to that can't use reflection refractions etc but the rest works in indy.