• 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 /
This question was closed Apr 20, 2016 at 03:42 PM by Zenyte for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Zenyte · Apr 20, 2016 at 12:09 PM · script error

Type `UnityEngine.Renderer' does not contain a definition for `color' and no extension method `color' of type `UnityEngine.Renderer' could be found (are you missing a using directive or an assembly reference?)

 public class ControlTitleScene : MonoBehaviour {
     
     public Transform targetPoint; //target camera move to point 
     public AudioSource bgm; //main background music
     public GameObject titleText,pressStart,buttonNew,buttonLoad,whiteScreen; //button,GUI
     public AudioClip buttonSound; //button sound effect
     
     //Private Variable
     private int titlePattern = 0;
     private float alpha = 0.5f;
     
     
     // Use this for initialization
     void Start () {
         
         //Set default variable
         alpha = 0.5f;
         whiteScreen.SetActive(true);
     
     }
     
     // Update is called once per frame
     void Update () {
         
         //Pan camera
         transform.position = Vector3.MoveTowards(transform.position, targetPoint.position, 3 * Time.deltaTime);    
         
         if(titlePattern == 0)
         {
             if(alpha > 0)
             {
                 alpha -= Time.deltaTime * 0.2f;
                 whiteScreen.GetComponent<Renderer>().color = new Color(.5f,.5f,.5f, alpha);
             }else
             {
                 bgm.Play();    
             }
             
             if(transform.position.z >= -27.0f)
             {
                 titlePattern = 1;
                 alpha = 0;
                 titleText.SetActive(true);
             }
             
         }
         
         if(titlePattern == 1)
         {
             if(alpha < 0.5f)
             {
                 alpha += Time.deltaTime * 0.5f;
                 titleText.GetComponent<Renderer>().color = new Color(.5f,.5f,.5f, alpha);
             }else
             {
                 titlePattern = 2;
                 pressStart.SetActive(true);    
             }
         }
         
         if(titlePattern == 2)
         {
             //Show press start
             
             if(Input.anyKey)
             {
                 pressStart.SetActive(false);
                 if(buttonSound != null)
                 {
                     AudioSource.PlayClipAtPoint(buttonSound,transform.position);    
                 }
                 titlePattern = 3;
             }
         }
         
         if(titlePattern == 3)
         {
             //Show button new game , load game
             buttonNew.SetActive(true);
             buttonLoad.SetActive(true);
         }
         
     }
 }
 
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

1 Reply

  • Sort: 
avatar image
1

Answer by Dave-Carlile · Apr 20, 2016 at 12:12 PM

The error message means what is says. The Renderer class doesn't have a color property. You are probably looking for Renderer.material, which does have a color property.

Comment
Add comment · Show 5 · 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 Zenyte · Apr 20, 2016 at 12:27 PM 0
Share

Could you help me please? I can't seem to know how to fix it I'm just a beginer at coding

avatar image Dave-Carlile Zenyte · Apr 20, 2016 at 12:36 PM 0
Share

Sure. One important thing about learning to code is the importance of looking at the documentation. If we go look at the documentation for the Renderer class we'll see a list of "variables" or "fields" that are valid for the class. If you look through that list you'll see that there isn't a field named color. But there is a field named material listed there.

Clicking on that field takes us to the description for it and we'll see that the data type for that class is $$anonymous$$aterial, and clicking on that link takes us to the documentation for the $$anonymous$$aterial class which shows the various fields belonging to that class.

The first one listed there is color. Clicking on that takes you to the description for that field including sample code for using it.

If any of these terms (field, class, etc.) are unknown to you then you should look for some C# program$$anonymous$$g tutorials on Google and take some time to learn them.

avatar image Zenyte Dave-Carlile · Apr 20, 2016 at 03:30 PM 0
Share

ins$$anonymous$$d of .color I put .material.color and it is working but the screen is white

Show more comments
avatar image NUKETheWay · Sep 02, 2020 at 10:36 AM 0
Share

where can I learn C# tutorials properly. I tried searching them everywhere. If I search beginner C# all I get is how to use if else for while loops and variables like int float char and the end of the tutorial. If I go for little more advanced tutorial then I end up getting too much difficult tutorials beyond. I just need to clear basics. So that I will be able to figure out stuff same as you did explained it. I ma facing same issue as above mentioned. Please suggest any tutorials you will find. Thank you

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

NullReferenceException, Script Error 1 Answer

how can i resolve this script inventary 1 Answer

How do I fix this error? 0 Answers

Error in my C# script, Help! 1 Answer

When i try to use transform.FindChild("Content").GetComponent(); it doesn't found it 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