- Home /
Change the tint of a texture by texture name?
 using UnityEngine;
 using System.Collections;
 
 public class PSColor : MonoBehaviour {
 
     void OnSetColor(Color color)
     {
         particleSystem.renderer.material.SetColor("_TintColor", color);
     }
     
     void OnGetColor(ColorPicker picker)
     {
         picker.NotifyColor(particleSystem.renderer.material.GetColor("_TintColor"));
     }
 }
 
This works on particles, but I can't figure out exactly what I need to get it to accept the name of a texture. All textures are on the 3D model, but I'd like to allow people to change the colors, but I don't know where to look or what to put in to get it to allow me to call by named textures.
 using UnityEngine;
 using System.Collections;
 
 
 public class ObjectColor : $$anonymous$$onoBehaviour {
 
     void OnSetColor(Color color)
     {
         Debug.Log("Hello", gameObject);
         $$anonymous$$aterial mt = new $$anonymous$$aterial(GetComponent<Renderer>().shared$$anonymous$$aterial);
         mt.color = color;
         GetComponent<Renderer>().material = mt;
     }
 
     void OnGetColor(ColorPicker picker)
     {
         picker.NotifyColor(GetComponent<Renderer>().material.color);
     }
 }
 
 
The code is this ins$$anonymous$$d of particle. But I still can't figure out how to call to shaders by name.
Answer by robertbu · Jun 16, 2014 at 04:15 AM
Coloring is a property of the shader, not of a texture. Many shaders don't use color at all, and the ones that do, typically use _Color rather than _Tintcolor. And it is up to the shader how the color is used. There is a shortcut if the color property is '_Color'. You can use Material.color:
 renderer.material.color = Color.red;
So the first step is to examine the materials/shaders on your 3D models to see if they have an _Color property. If not, you may have to change the shader you use for your 3D models to get a color overlay. Then you can use material.SetColor() or material.color to set the color.
I do have a color property on them. All the shaders have names, but I can't seem to be able to call to the names of the shaders. Like I have one called Pupil and one called Iris. I'd like to be able to call to the shader by name so it is changed.
Answer by Menatombo · Jun 16, 2014 at 08:12 PM
Wow. Well, I completely forgot that Unity doesn't go by names for almost anything. I got it working by using an array instead of trying to use the names of the shaders!
Your answer
 
 
             Follow this Question
Related Questions
Select UV map 0 Answers
3D model texture 1 Answer
Trying to use multiple png files for a single texture 0 Answers
Uploading textures to be used for 3d model at runtime? 0 Answers
Car Model Run time Color Change Problem 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                