Hi all,
I am working on a game built from one scene.
this scene includes a canvas(called StartMenu) that is basically “covering” the game scene.
when the user puts his finger on the right spot, the canvas disappears(using StartMenu.SetActive (false)) and the game starts.
I am trying to make the transition “smooth” by adding a fading effect.
I attached the canvas with a script from the following tutorial:
I am having problems activating the method FadeMe() for this specific Canvas.
this is how iv’e been trying to access it:
If(GameStarted)
{
GameObject go = GameObject.Find("StartCanvas");
fadeScript = go.GetComponent<Fade>();
fadeScript.FadeMe();
}
what happens is that, when the user puts his finger to start the game, you can see the score started increasing but the StartMenu canvas is not fading.
What am I missing here?
Edited(31.5):
Following is the code attached on the Canvas game object
using UnityEngine;
using System.Collections;
public class Fade : MonoBehaviour {
public void FadeMe(){
StartCoroutine (doFade ());
}
IEnumerator doFade(){
CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
while(canvasGroup.alpha > 0){
canvasGroup.alpha -= Time.deltaTime / 2;
yield return null;
}
canvasGroup.interactable = false;
yield return null;
}
}