Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by importguru88 · Aug 31, 2016 at 12:49 PM · scripting problemerrorscript error

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";
  }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DiegoSLTS · Aug 31, 2016 at 12:58 PM

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image importguru88 · Aug 31, 2016 at 03:29 PM 0
Share

I made all most of the errors go away . I only have one error .

(8,10): error CS0246: The type or namespace name `TextElement' could not be found. Are you missing a using directive or an assembly reference?

I see why it would . How would I declare TextElement ? Here is my code now :

 using UnityEngine;
  using System.Collections;
  using UnityEngine.UI;
  
  public class fly : $$anonymous$$onoBehaviour {
  
   public CanvasGroup canvasGroup;
   public TextElement textElement;
 
  
  
       void Show$$anonymous$$essage(string message, float timeToShow = 10)
   {
       StartCoroutine(Show$$anonymous$$essageCoroutine(message, timeToShow));
   }
      
       IEnumerator Show$$anonymous$$essageCoroutine(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";
   }
  }
  
avatar image DiegoSLTS importguru88 · Aug 31, 2016 at 04:03 PM 0
Share

TextElement is not a type, Text is a type and I guess you want that. I think you have to learn about the syntax of C# before doing actual things using Unity features, this are pretty basic things that you're missing, you'll have a lot of this problems if you don't know what a type, a definition and stuff like that really mean.

For example, you have a line that says:

 public Game

That won't work, it's like the first part of defining a variable but only that doesn't mean anything. You either remove that or put a name for that variable, and a semicolon at the end, like this:

 public Game game;

And that works only if you have a class called "Game" defined somewhere in your project.

avatar image importguru88 · Aug 31, 2016 at 04:17 PM 0
Share

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

avatar image
0

Answer by importguru88 · Aug 31, 2016 at 04:16 PM

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 ?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by $$anonymous$$ · Aug 11, 2018 at 11:12 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

77 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

(31,16): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `=' 2 Answers

BCE0044: expecting ''', found '\r'. 1 Answer

Getting weird error message!?!?!? 1 Answer

How do i fix this error? Cannot implicitly convert type `Sprite' to `UnityEngine.Sprite' 1 Answer

error CS0120: An object reference is required to access non-static member `TextManagerLvl1.currentState' 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges