Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- [RequireComponent(typeof(Image))]
- public class RarityBorderAnimator : MonoBehaviour
- {
- [Tooltip("Assign a material configured for scrolling UVs.")]
- [SerializeField] private Material borderMaterial;
- [Tooltip("Speed at which the texture will scroll horizontally.")]
- [SerializeField] private float scrollSpeed = 0.5f;
- private Material runtimeMaterial;
- void Start()
- {
- // Double the scale so it obviously repeats
- runtimeMaterial.mainTextureScale = new Vector2(5f, 5f);
- }
- void Awake()
- {
- // Make a runtime copy of the material
- runtimeMaterial = Instantiate(borderMaterial);
- // Assign that copy to the Image
- Image image = GetComponent<Image>();
- image.material = runtimeMaterial;
- }
- void Update()
- {
- // Just apply the global offset from InventoryManager
- float offset = InventoryManager.globalSwirlOffset;
- runtimeMaterial.mainTextureOffset = new Vector2(offset, offset);
- runtimeMaterial.mainTextureScale = new Vector2(5f, 5f);
- }
- public void SetMaterial(Material newMat)
- {
- // If you want to update mid-runtime, you can reassign the runtime material
- if (runtimeMaterial != null) Destroy(runtimeMaterial);
- runtimeMaterial = Instantiate(newMat);
- GetComponent<Image>().material = runtimeMaterial;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement