Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class ChangeLerpTexture : MonoBehaviour
- {
- [SerializeField] Material m_fieldMaterial;
- [SerializeField] string parameterName = "_LerpValue";
- [SerializeField] float m_deltaTimer = 0.005f; // Можно float m_deltaTimer = Time.deltaTime;
- private float m_timer;
- private void Start ()
- {
- m_fieldMaterial = GetComponent<Renderer> ().material;// не обязательно если указать m_fieldMaterial в Инспеторе
- ChangeTexture ();
- }
- // Можешь вызвать через GameEventListener и/или AnimatorCallAnimationEvents
- public void ChangeTexture ()
- {
- StopAllCoroutines();
- StartCoroutine (cr_ChangeTexture ());
- }
- IEnumerator cr_ChangeTexture ()
- {
- yield return new WaitForSeconds (2f);
- while (m_timer < 1f)
- {
- m_fieldMaterial.SetFloat (parameterName, m_timer);
- m_timer += m_deltaTimer;
- yield return null; // что бы срабатывало на каждом кадре и не завило
- }
- m_timer = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment