rabidus-test/Assets/DissolveEffect.cs

37 lines
841 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DissolveEffect : MonoBehaviour
{
public float Time;
List<Renderer> _renderer = new List<Renderer>();
public string Param = "_Dissolve";
public float From = 0;
public float To = 1;
void Start()
{
_renderer.AddRange(GetComponentsInChildren<Renderer>());
}
private bool _action = false;
[ContextMenu("Dissolve")]
public void Dissolve()
{
LeanTween.value(From, To, Time).setOnUpdate((float x) =>
{
for (int i = 0; i < _renderer.Count; i++)
{
for (int h = 0; h < _renderer[i].materials.Length; h++)
{
_renderer[i].materials[h].SetFloat(Param, x);
}
}
});
}
}