Advertisement
TGM_XLANDC

Unity Fade Script

Jan 4th, 2025
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | Source Code | 0 0
  1. IEnumerator CorutineName(float time)
  2. {
  3.     for (float t = 0; t < 1; t += Time.deltaTime / time)
  4.     {
  5.         //For moving object to a position to another in time
  6.         transform.position = Vector3.Lerp(beginPos, endPos, t);
  7.  
  8.         //Modifing transparency of black image (from transparent to opaque)
  9.         selectedImage.color = new Color(0.0f,0.0f,0.0f,Mathf.Lerp(0.0f,1.0f,t));
  10.  
  11.         //Modifing transparency of canvas group (from transparent to opaque)
  12.         canvasGroup.alpha = Mathf.Lerp(0.0f,1.0f,t);
  13.         yield return null;
  14.     }
  15. }
Tags: C# Unity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement