Pro_Unit

ChangeLerpTexture

Feb 17th, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System.Collections;
  2.  
  3. using UnityEngine;
  4.  
  5. public class ChangeLerpTexture : MonoBehaviour
  6. {
  7.     [SerializeField]  Material m_fieldMaterial;
  8.     [SerializeField] string parameterName = "_LerpValue";
  9.     [SerializeField]  float m_deltaTimer = 0.005f; // Можно float m_deltaTimer = Time.deltaTime;
  10.     private float m_timer;
  11.  
  12.     private void Start ()
  13.     {
  14.         m_fieldMaterial = GetComponent<Renderer> ().material;// не обязательно если указать m_fieldMaterial в Инспеторе
  15.         ChangeTexture ();
  16.     }
  17.     // Можешь вызвать через GameEventListener и/или AnimatorCallAnimationEvents
  18.     public void ChangeTexture ()
  19.     {
  20.         StopAllCoroutines();
  21.         StartCoroutine (cr_ChangeTexture ());
  22.     }
  23.     IEnumerator cr_ChangeTexture ()
  24.     {
  25.  
  26.         yield return new WaitForSeconds (2f);
  27.         while (m_timer < 1f)
  28.         {            
  29.             m_fieldMaterial.SetFloat (parameterName, m_timer);
  30.             m_timer += m_deltaTimer;
  31.             yield return null; // что бы срабатывало на каждом кадре и не завило
  32.         }
  33.         m_timer = 0;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment