- Home /
Scrolling Sprite Image
I'm creating a conveyor belt for my 2D top down game. I'd like to create something like the conveyor belts from the game Factorio
, but I'd like to do it using one image in comparison to animating it with multiple ones.
To do this I would like to have a sprite with a repeating texture that loops. Essentially like having a scrolling background in a platformer game but instead having it for one sprite object.
I've looked at tutorials for how it can be done with scrolling backgrounds but instead of one sprite they just have multiple moving sprites and create new ones as the character moves left or right.
I've been looking around for tutorials on this but can't seem to find anything.
I've tried changing the texture offset but the it doesn't repeat the texture and only slides it right. It would need to deal with being rotated too.
public float animationSpeed = -0.2f;
private Material _material;
private BoxCollider2D boxCollider2D;
void Start()
{
boxCollider2D = GetComponent<BoxCollider2D>();
_material = GetComponent<SpriteRenderer>().material;
}
void Update()
{
_material.mainTextureOffset = new Vector2(Time.time * animationSpeed, 0);
//GetComponent<Renderer>().material.mainTextureOffset = offset;
}
How can this be done?
Your answer
Follow this Question
Related Questions
Texturing custom 2d sprite 0 Answers
(C#) Help with Spriterenderer.sprite 2 Answers
Unity streching sprite gameobject to fit two positions. 1 Answer
Multiple Cars not working 1 Answer