Skip to content

Instantly share code, notes, and snippets.

@FeniXb3
Created September 7, 2015 20:51
Show Gist options
  • Save FeniXb3/bb04e5601b9949ab03fe to your computer and use it in GitHub Desktop.
Save FeniXb3/bb04e5601b9949ab03fe to your computer and use it in GitHub Desktop.
Small component for Unity3d that is responsible for looping texture on the gameobject. The gameobject that has uses this component needs a renderer with material that has a texture you want to use.
using UnityEngine;
public class TextureOffsetController : MonoBehaviour
{
public float speed = 0.05f;
private float position = 0.0f;
void Update()
{
position += speed;
if (position > 1.0f)
{
position -= 1.0f;
}
GetComponent<Renderer>().material.mainTextureOffset = new Vector2(0.0f, position);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment