Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // script that fades over time when pressed T or whatever the option you like use it to fade an object
  2. //
  3.  
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEngine;
  7.  
  8. public class FadeObject : MonoBehaviour {
  9.  
  10. void update ()
  11. {
  12. if(Input.GetKeyUp(KeyCode.T))
  13. {
  14. StartCoroutine(FadeTo(0.0f, 1.0f));
  15. }
  16. if(Input.GetKeyUp(KeyCode.F))
  17. {
  18. StartCoroutine(FadeTo(1.0f, 1.0f));
  19. }
  20. }
  21.  
  22. IEnumerator FadeTo(float aValue, float aTime)
  23. {
  24. float alpha = transform.GetComponent<Renderer>().material.color.a;
  25. for (float t = 0.0f; t < 1.0f; t += Time.deltaTime / aTime)
  26. {
  27. Color newColor = new Color(1, 1, 1, Mathf.Lerp(alpha,aValue,t));
  28. transform.GetComponent<Renderer>().material.color = newColor;
  29. yield return null;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement