error CS0103: The name `canvasGroup' does not exist in the current context

I trying to get the text to show and disappear in my scene . When I have save the script I have gotten five of the same errors .

(18,13): error CS0103: The name timeShown' does not exist in the current context (16,6): error CS0103: The name canvasGroup’ does not exist in the current context
(17,6): error CS0103: The name textElement' does not exist in the current context (23,6): error CS0103: The name canvasGroup’ does not exist in the current context
(24,6): error CS0103: The name `textElement’ does not exist in the current context

Here is my script :

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class fly : MonoBehaviour {
public Game 


	 void ShowMessage(string message, float timeToShow = 10)
 {
     StartCoroutine(ShowMessageCoroutine(message, timeToShow));
 }
	
	 IEnumerator ShowMessageCoroutine(string message, float timeToShow = 10)
 {
     canvasGroup.alpha = 1;
     textElement.text = message;
     while (timeShown < timeToShow)
     {
         timeShown += Time.deltaTime;
         yield return null;
     }
     canvasGroup.alpha = 0;
     textElement.text = "The points require for this level is 2500";
 }
}

Those variables are not defined, that’s what the error is saying. It looks like you copy pasted some code, but forgot to copy the definition of the variables. You need something like:

public CanvasGroup canvasGroup;

At the top, inside the class body, and then in the inspector you must drag an object from the scene with a CanvasGroup attached intobthe field that appears for that variable. You need something similar for the other variables. Or check the original source of the code and check there how it’s done.

If want to do just U.I text . How do I make it appear on scene like seconds later and disappear in a couple of seconds ?

i do also have the same error. How can we avoid it when importing resources ?