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!
What errors do you see in the console?
Assets/ExampleBehaviorScript.cs(10,36): error CS0619: ‘UnityEngine.GameObject.renderer’ is obsolete: ‘Property renderer has been deprecated. Use GetComponent()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()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()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?)
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?
Yes, it says its Unity 5.1.2f1 personal.
“.renderer” is no longer a member of the GameObject class. It used to be a shortcut for calling GetComponent(), but now it isn’t, so you need to use the GetComponent() 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.
I tried running API updater, it’s disabled. Where is the GetComponent()? I tried ctrl ', but do you have a link?
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()”- 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.
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.
1 Like