Advertisement
CirilXD

Unity Scene Transition Interactible Map

Jul 24th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. //----IMPORTANT MULTPLE SCRIPTS AHEAD!!!!----
  2.  
  3. //SceneManager.cs----------------------------------------------------------
  4. //----------------------------------------------------------
  5. //----------------------------------------------------------
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using System.Collections;
  9.  
  10. public class SceneManager : MonoBehaviour
  11. {
  12.     public GameObject transitionGO;
  13.  
  14.     bool isFadingIn = true;
  15.     public GameObject current;
  16.  
  17.     public void TransformToImage(GameObject target){
  18.         StartCoroutine(FadeInAndOut(target));
  19.     }
  20.  
  21.     IEnumerator FadeInAndOut(GameObject target){
  22.         int fadeSpeed = 3;
  23.         Image transitionImage = transitionGO.GetComponent<Image>();
  24.         transitionImage.raycastTarget = true;
  25.         Color transitionColor = transitionImage.color;
  26.  
  27.         while (isFadingIn) {
  28.             transitionColor.a += fadeSpeed * Time.deltaTime;
  29.             if (transitionColor.a >= 1) {
  30.                 isFadingIn = false;
  31.                 transitionColor.a = 1;
  32.             }
  33.             transitionImage.color = transitionColor;
  34.             yield return new WaitForEndOfFrame();
  35.         }
  36.         transitionImage.raycastTarget = false;
  37.         current.SetActive(false);
  38.         target.SetActive(true);
  39.         current = target;
  40.  
  41.         while (!isFadingIn) {
  42.             transitionColor.a -= fadeSpeed * Time.deltaTime;
  43.             if (transitionColor.a <= 0) {
  44.                 transitionColor.a = 0;
  45.                 isFadingIn = true;
  46.             }
  47.             transitionImage.color = transitionColor;
  48.             yield return new WaitForEndOfFrame();
  49.         }
  50.        
  51.     }
  52. }
  53. //CustomButton.cs----------------------------------------------------------
  54. //----------------------------------------------------------
  55. //----------------------------------------------------------
  56. using UnityEngine;
  57. using UnityEngine.UI;
  58.  
  59. public class CustomButton : MonoBehaviour
  60. {
  61.     // Start is called before the first frame update
  62.     void Start()
  63.     {
  64.         this.GetComponent<Image>().alphaHitTestMinimumThreshold = 0.1f;
  65.     }
  66.  
  67. }
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement