UvScroller.cs 706 B

123456789101112131415161718192021222324252627
  1. using UnityEngine;
  2. namespace FlatKit {
  3. public class UvScroller : MonoBehaviour {
  4. public Material targetMaterial;
  5. public float speedX = 0f;
  6. public float speedY = 0f;
  7. private Vector2 offset;
  8. private Vector2 initOffset;
  9. void Start() {
  10. offset = targetMaterial.mainTextureOffset;
  11. initOffset = targetMaterial.mainTextureOffset;
  12. }
  13. void OnDisable() {
  14. targetMaterial.mainTextureOffset = initOffset;
  15. }
  16. void Update() {
  17. offset.x += speedX * Time.deltaTime;
  18. offset.y += speedY * Time.deltaTime;
  19. targetMaterial.mainTextureOffset = offset;
  20. }
  21. }
  22. }