using UnityEngine; using DG.Tweening; public class Materials : MonoBehaviour { public GameObject target; public Color toColor; Tween colorTween, emissionTween, offsetTween; void Start() { // NOTE: all tweens will be created in a paused state, so they can be toggled via the UI // Store the material, since we will tween that Material mat = target.GetComponent().material; // COLOR colorTween = mat.DOColor(toColor, 1).SetLoops(-1, LoopType.Yoyo).Pause(); // EMISSION // Note that the float value you see in Unity's inspector, next to the emission's color, // doesn't really exist in the shader (it's generated by Unity's inspector and applied to the material's color), // se we have to tween the full _EmissionColor. emissionTween = mat.DOColor(new Color(0, 0, 0, 0), "_EmissionColor", 1).SetLoops(-1, LoopType.Yoyo).Pause(); // OFFSET // In this case we set the loop to Incremental and the ease to Linear, because it's cooler offsetTween = mat.DOOffset(new Vector2(1, 1), 1).SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental).Pause(); } // Toggle methods (called by UI events) public void ToggleColor() { colorTween.TogglePause(); } public void ToggleEmission() { emissionTween.TogglePause(); } public void ToggleOffset() { offsetTween.TogglePause(); } }