Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
10
Question by Fred_Vicentin · Feb 24, 2015 at 07:33 PM · materialunity5renderer

[CLOSED]Unity 5 GameObject.Renderer.Material

Did something changed on Unity 5 ?

I know how to do this another ways but I don't know why this is not working:

I'm trying to change the GameObject color using

 gameObject.renderer.material

but it gives error : "error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement"

**EDIT: UNITY changed this, now to use 'gameObject.renderer.material' you need to change to

 gameObject.GetComponent<Renderer>().material

Thats my entire code:

 using UnityEngine;
 using System.Collections;
 
 public class RiftRay : MonoBehaviour {
     public LayerMask mask;
     
     public GameObject[] pisos;
     
     public int distance;
     void Update () 
     {
         
         Vector3 fwd = transform.TransformDirection(Vector3.forward);
         Debug.DrawRay(transform.position, fwd, Color.green);
         if (Physics.Raycast(transform.position, fwd, distance ,mask ))
         {
                 print("a");        
             
                 pisos[0].renderer.material.color = Color.black;
         }
         
             
     }
 }
 

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

4 Replies

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

Answer by tanoshimi · Feb 24, 2015 at 07:45 PM

That's nothing to do with Unity 5; that's just bad code. Line 19 should read:

 pisos[0].renderer.material.color = Color.black;
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 Fred_Vicentin · Feb 24, 2015 at 07:50 PM 0
Share

Sorry, was my bad now, the error is: error CS0619: UnityEngine.GameObject.renderer' is obsolete: Property renderer has been deprecated. Use GetComponent() ins$$anonymous$$d. (UnityUpgradable)'

avatar image Fred_Vicentin · Feb 24, 2015 at 07:51 PM 1
Share

I changed to pisos[0].GetComponent().material.color = Color.black; and worked

avatar image BlueberryBoll · Jul 27, 2017 at 09:17 PM 1
Share

As others have noted, this is no longer a valid answer. Everyone should look at the answers below ins$$anonymous$$d.

avatar image
20

Answer by cesarureno · Mar 17, 2015 at 08:28 AM

 GetComponent<Renderer>().material.color = Color.black;

Try this

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
3

Answer by TrollAxeThrower · Sep 16, 2015 at 03:36 PM

cesarureno's answer didn't work for me. just this one:

 GetComponent<Renderer>().materials[0].color = Color.Black;

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 Gravn · Jul 16, 2015 at 10:41 PM

http://docs.unity3d.com/ScriptReference/Renderer-material.html GRR Unity

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

23 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

Related Questions

Changing two different objects renderer colour 1 Answer

Are Mesh Filters Really Necessary? 1 Answer

Trying to make a side scroller. I'm following a tutorial and getting this error. 1 Answer

Gameobject not the right color 0 Answers

How to Set Custom UI Image Material Render Order? 0 Answers


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