Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 706

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 706

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 706

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 706

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 706

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 706

Warning: Cannot modify header information - headers already sent by (output started at /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php:706) in /var/www/brackeys.com/forum/wp-content/themes/forumengine/includes/front.php on line 646
How to change the color of a material in Unity with a button click | Brackeys Forum

How to change the color of a material in Unity with a button click

Updated on January 21, 2020 in Unity
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on January 20, 2020

Hi, i’m new to Unity and I am currently messing around with it to get some experience. I have followed a few of Brackeys’s guides and have watched a few tutorials but I am not that experienced yet.

For the past few days, I have been trying to figure out how to change the color of a material when I click a button in Unity. I keep trying to look onto other forums, look onto tutorials and guides, but none of them seem to help me. I have tried to ask for help from others but I cannot seem to get a straight answer, and I am just told to go watch a seventeen minute video talking about methods in c# or something.

I know this might seem like a small issue, but I only have a few weeks of experience and I literally cannot get a direct answer to what is wrong with my code even from an actual person. If someone could just tell me what I am doing wrong, how I can fix it, and what to think about in the future, that would be awesome. Anyways, here’s my code:


public void ColorChanger(string color, Color blue) { Material.SetColor = Color.blue; }
Thanks!

  • Liked by
Reply
0 on January 20, 2020

heres an image of the code: https://imgur.com/a/8JmPQuJ

  • Liked by
Reply
Cancel
2 on January 21, 2020

You can’t change the color of the material directly of an object. You have to get the renderer of an object and then change it’s material color. Do something like this:

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

 

on January 21, 2020

ill be sure to try this

on January 21, 2020

so iv’e replaced the script but its still not working? i assume im doing something wrong outside of the script

Show more replies
  • Liked by
Reply
Cancel