Skip to content

Instantly share code, notes, and snippets.

@lordlycastle
Created June 12, 2020 19:36
Show Gist options
  • Save lordlycastle/9ed26aac7770835ae9c73e547497d09d to your computer and use it in GitHub Desktop.
Save lordlycastle/9ed26aac7770835ae9c73e547497d09d to your computer and use it in GitHub Desktop.
Tween any float material property with help of DOTween! πŸŒ€
using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine;
public class MaterialsFloatTweener : MonoBehaviour
{
[InlineEditor()]
public Material material;
public string name;
public float duration;
public float from;
public float to;
public bool autoPlay;
public Ease tweenEase = Ease.Linear;
[InfoBox("-1 means forever")] public int loops = -1;
public LoopType loopType = LoopType.Yoyo;
public Tween tween;
private void Start()
{
tween = DOTween.To(value => material.SetFloat(name, value), @from, to, duration)
.SetLoops(loops, loopType)
.SetEase(tweenEase);
if (autoPlay)
tween.Play();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment