I have to draw 2D sprites that follow a 3d object for a school project we are doing in Unity. It should look like something like this:

I am somewhat new to the whole 2d on 3d integration. I have the images (about 15) so I need to know how to create a method that can loop these images during run time. So, can someone show me a good starting point on how I should go about this? Thank you in advance.
3 Answers
3
Create a quad/plane and put a material on that quad/plane
with frame 1 attached. Make sure that all the frame pictures
are in separate picture files & that the dimensions(x & y) are the same
from frame 1 till 5. Assign them in the inspector.
using UnityEngine;
using System.Collections;
public class SwitchBitmap : MonoBehaviour {
public float frameSwitchSpeed = 0.25f;
public Texture[] sprites;
void Start()
{
UpdateSprite(0);
}
void UpdateSprite(int i)
{
renderer.material.mainTexture = sprites*;*
yield return new WaitForSeconds(frameSwitchSpeed);
UpdateSprite (i);
}
}
For Unity 4.3, you are on the right track with the Sprite Renderer. And x_ivan_x@live.nl’s class will work if you want a scripting method, however, there is now a different (and I think easier) way.
- In the Project window, select all your textures for the animation.
- In the Inspector window, click on the Texture Type drop down box and select Sprite.
- (If you know what settings you want for the textures, go ahead and do that as well)
- Press Apply.
- Go back to the Project window. With all the textures selected, drag them into an empty space in the Hierarchy.
- Save the animation at the prompt.
- You can now edit the animation in the Animation window and trigger it using scripts and the Animator window.
This is the solution to my problem. Many thanks to the people who responded.
public Texture2D[] mSprites;
private Texture2D currentSprite;
private int counter;
public float switchTime = 0.5f;
public Rect r_Sprite;
void Start(){
counter = 0;
StartCoroutine("SwitchSprite");
}
void OnGUI(){
GUI.DrawTexture(r_Sprite,currentSprite);
}
private IEnumerator SwitchSprite(){
currentSprite = mSprites[counter];
if(counter < mSprites.Length){
counter++;
}else{
counter = 0;
}
yield return new WaitForSeconds(switchTime);
StartCoroutine("SwitchSprite");
}
The class runs fine but there is an issue where the sprites are not being drawn on the screen. Is there something I may have missed???
– mmangual_83How do I get the quad/plane? I am very new at this
– mmangual_83do i write the lookup all in the same sprite animator class?
– mmangual_83Do you have skype? That would probably work better.
– x_ivan_x_live.nl