43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DissolveAnimator : MonoBehaviour
|
|
{
|
|
public string m_propertyName = "_Threshold";
|
|
int m_proprtyId = -1;
|
|
public float m_threshold = 0f;
|
|
float m_prevThreshold = -1f;
|
|
Material m_Mat;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
var r = GetComponent<Renderer>();
|
|
if (!r)
|
|
{
|
|
Debug.LogError("No renderer found!");
|
|
enabled = false;
|
|
return;
|
|
}
|
|
m_Mat = r.material;
|
|
m_proprtyId = m_Mat.shader.FindPropertyIndex(m_propertyName);
|
|
if (m_proprtyId < 0)
|
|
{
|
|
Debug.LogError("Property with property name: " + m_propertyName + " not found!");
|
|
enabled = false;
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void LateUpdate()
|
|
{
|
|
if (m_prevThreshold != m_threshold)
|
|
{
|
|
m_prevThreshold = m_threshold;
|
|
m_Mat.SetFloat("_Threshold", m_threshold);
|
|
|
|
//m_Mat.SetFloat(m_proprtyId, m_threshold);
|
|
}
|
|
}
|
|
}
|