UVscroll.cs 772 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class UVscroll : MonoBehaviour
  5. {
  6. // Scroll main texture based on time
  7. public int materialId = 0;
  8. public float scrollSpeedX = 0.5f;
  9. public float scrollSpeedY = 0.5f;
  10. Renderer rend;
  11. void Start()
  12. {
  13. rend = GetComponent<Renderer>();
  14. }
  15. void Update()
  16. {
  17. //GetComponent<LineRenderer>().materials[0].
  18. float offsetX = Time.time * scrollSpeedX;
  19. float offsetY = Time.time * scrollSpeedY;
  20. rend.materials[materialId].SetTextureOffset("_MainTex", new Vector2(offsetX, offsetY));
  21. //rend.material.SetTextureOffset("_MainTex", new Vector2(offsetX, offsetY));
  22. }
  23. }