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 /
This question was closed Mar 08, 2015 at 11:50 PM by KnightRiderGuy for the following reason:

Found a solution

avatar image
0
Question by KnightRiderGuy · Feb 24, 2015 at 10:54 PM · gameobjectbuttonrenderermaterial rendererchange material

Change Object Material With a button C#

I'm trying to figure out how to change the material on an object using a button, so far I have this but I'm not fully understanding the reference to the game object that needs the material changed.

 using UnityEngine;
 using System.Collections;
 
 public class VideoScreenManager : MonoBehaviour {
 
     //Material Reference
     public Material newMaterialRef01;
     public Material newMaterialRef02;
     public Material newMaterialRef03;
     public Material newMaterialRef04;
     public Material newMaterialRef05;
     public Material newMaterialRef06; //Default White Material
 
     public void  GoColor01(){
 
         gameObject.name=("VideoPlayerScreen").renderer.material.color = newMaterialRef01;
     }
 }
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
0

Answer by Jessespike · Feb 24, 2015 at 10:57 PM

You're trying to set a color property with a material.

Try this:

 gameObject.name=("VideoPlayerScreen").renderer.material = newMaterialRef01;

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 KnightRiderGuy · Feb 24, 2015 at 11:01 PM 0
Share

I get this error Jessespike:

Assets/VideoScreen$$anonymous$$anager.cs(16,55): error CS1061: Type string' does not contain a definition for renderer' and no extension method renderer' of type string' could be found (are you missing a using directive or an assembly reference?)

avatar image KnightRiderGuy · Feb 24, 2015 at 11:22 PM 0
Share

I even tried putting a public reference to the game object and that still did not work??

avatar image KnightRiderGuy · Feb 25, 2015 at 12:30 AM 0
Share

$$anonymous$$aybe it did not like that my VideoPlayerScreen game object was a child of a panel on a canvas because if I drag the script that was on my game manager outside of the canvas and put in directly on the VideoPlayerScreen game object and I just do this this way it works? Well it changes my materials anyway but not doing exactly what I wanted with the Video Texture script. I was trying to see if I could get buttons to change the video screen texture that the web cam plays on because the effect is cool but it does not work the way I want.... but that is another question all together though.

public void GoColor02(){ renderer.material = new$$anonymous$$aterialRef02;

 }

It works

Follow this Question

Answers Answers and Comments

20 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

Related Questions

How to find the index of the clicked UI button? 1 Answer

Children of DualTouchControls prefab keep being forced to active 0 Answers

Changing gameobject material color makes object disappear from view. How can I fix this? 1 Answer

Material class use general question 1 Answer

DontDestory gameobject doesn't work on button click after a new scene loads 2 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