Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need help starting the script tutorial

Discussion in 'Scripting' started by Jamestown02, Aug 8, 2015.

  1. Jamestown02

    Jamestown02

    Joined:
    Aug 8, 2015
    Posts:
    5
    https://unity3d.com/learn/tutorials...cripts-as-behaviour-components?playlist=17117
    I go to this first tutorial, which is changing the colors of the cube in the play screen.

    I try to play it, but it says "All compiler errors have to be fixed before you can enter play mode!"
    I get about 6 error messages.

    But I take the script from below the video, I cut and paste! What more do I have to do?
    -Before that, I assign the script to the cube, which I first add the rigid body component. And I put the plane under the cube.

    What more can I do? I've watched the video, and I've cut and paste the code from below!
     
  2. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    What errors do you see in the console?
     
  3. Jamestown02

    Jamestown02

    Joined:
    Aug 8, 2015
    Posts:
    5
    Assets/ExampleBehaviorScript.cs(10,36): error CS0619: 'UnityEngine.GameObject.renderer' is obsolete: 'Property renderer has been deprecated. Use GetComponent<Renderer>()instead.(UnityUpgradable)'
    Assets/ExampleBehaviorScript.cs(10,45): error CS1061: Type 'UnityEngine.Component' does not contain a definition for 'material' and no extension method 'material' of type 'UnityEngine.Component' could be found (are you missing a using directive or assembly reference?)
    Assets/ExampleBehaviorScript.cs(14,36): error CS0619: 'UnityEngine.GameObject.renderer' is obsolete: 'Property renderer has been deprecated. Use GetComponent<Renderer>()instead.(UnityUpgradable)'
    Assets/ExampleBehaviorScript.cs(14,45): error CS1061: Type 'UnityEngine.Component' does not contain a definition for 'material' and no extension method 'material' of type 'UnityEngine.Component' could be found (are you missing a using directive or assembly reference?)
    Assets/ExampleBehaviorScript.cs(18,36): error CS0619: 'UnityEngine.GameObject.renderer' is obsolete: 'Property renderer has been deprecated. Use GetComponent<Renderer>()instead.(UnityUpgradable)'
    Assets/ExampleBehaviorScript.cs(18,45): error CS1061: Type 'UnityEngine.Component' does not contain a definition for 'material' and no extension method 'material' of type 'UnityEngine.Component' could be found (are you missing a using directive or assembly reference?)
     
  4. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    I'm not at my unity machine right now, if nobody chimes in by later I might test and see if it works for me. Another question - are you using unity 5?
     
  5. Jamestown02

    Jamestown02

    Joined:
    Aug 8, 2015
    Posts:
    5
    Yes, it says its Unity 5.1.2f1 personal.
     
  6. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    ".renderer" is no longer a member of the GameObject class. It used to be a shortcut for calling GetComponent<Renderer>(), but now it isn't, so you need to use the GetComponent<Renderer>() call instead. It says this in the error pretty clearly, and it also states that it's upgradable. In your Unity menu if you go to "Assets -> Run API Updater" it should allow you to update all of those deprecated entries automatically.
     
  7. Jamestown02

    Jamestown02

    Joined:
    Aug 8, 2015
    Posts:
    5
    I tried running API updater, it's disabled. Where is the GetComponent<Renderer>()? I tried ctrl ', but do you have a link?
     
  8. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    If you double click the error, it'll open the script and take you to where the problem is occurring. When you get there, take the ".renderer" and replace it with "GetComponent<Renderer>()"- then go back and do the same thing for the remaining errors. I don't know what "ctrl ' " is supposed to be or what you're talking about with links, but if you want more info on the Renderer component you can find it here.
     
  9. Jamestown02

    Jamestown02

    Joined:
    Aug 8, 2015
    Posts:
    5
    I got it to work! Here's my problem I've had: The script's name was "Colors", and the Public Class was named something else "Example Script". So, I changed the Public Class name to match the script name "Colors".

    Problem solved. Thanks.
     
    KingLlama likes this.