How do you get a color from another game object
I'm working on a paintball game. Where the object that I shoot must get the color that the paintbal in the game has. The paintball color change the hole time so I can't say that the object must change in a specific color.
my code on the moment is:
but when I run the game I get this error:
I have checked that he can find the object kleur so that isn't the problem. I hope someone can help me.
Answer by hexagonius · Feb 14, 2017 at 12:40 PM
The Problem is that Material is not a component itself. It's part of any Renderer. So you'd need to do the following:
GetComponent<Renderer>().material.color = kubus.GetComponent<Renderer>().material.GetColor("_Color");
P.S.: The left hand side was right already, why did you change syntax on the other?
P.P.S.: Paste your code using the "101010" button next time, making it copyable.
Your answer
Follow this Question
Related Questions
Layered Material / Shader / Texture for realtime manipulation of part of a texture. 0 Answers
How can i make a tiled/striped texture on a sphere ? (see example below) 0 Answers
Change Texture From World Position Amplify Shader 0 Answers
Imported meshes colors changed to blue. How do I fix them? 2 Answers
Material.SetTexture doesn't work if not "_MainTex" 0 Answers