rabidus-test/Assets/ShaderGraph_Dissolve/Utility/Scripts/DissolveChilds.cs

55 lines
1.3 KiB
C#
Raw Normal View History

2023-10-17 14:17:56 +03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DissolveExample
{
public class DissolveChilds : MonoBehaviour
{
// Start is called before the first frame update
List<Material> materials = new List<Material>();
bool PingPong = false;
void Start()
{
var renders = GetComponentsInChildren<Renderer>();
for (int i = 0; i < renders.Length; i++)
{
materials.AddRange(renders[i].materials);
}
}
private void Reset()
{
Start();
SetValue(0);
}
// Update is called once per frame
void Update()
{
var value = Mathf.PingPong(Time.time * 0.5f, 1f);
SetValue(value);
}
//IEnumerator enumerator()
//{
// //float value = while (true)
// //{
// // Mathf.PingPong(value, 1f);
// // value += Time.deltaTime;
// // SetValue(value);
// // yield return new WaitForEndOfFrame();
// //}
//}
public void SetValue(float value)
{
for (int i = 0; i < materials.Count; i++)
{
materials[i].SetFloat("_Dissolve", value);
}
}
}
}