Question by
ResourceV · Nov 19, 2015 at 12:22 PM ·
c#scripting problemobjects
Accessing objects in C#
This may sound a bit idiot, but... In C#, when am I accessing an object and when am I just taking its value ?
For example:
Renderer ren = GetComponent<Renderer>();
/*
*this sets ren to the GameObject's renderer.ç
*If I change something in the var it will change also in the renderer.
*/
But, the thing is this:
Texture2D tex = GetComponent<Renderer>().material.mainTexture ;
/*
*This dont set the var as the material's main texture
*It just duplicates it and puts it into the var,
*so, if I change something in the var, the main texture won't change
*/
So, how do I know if I'm pointing to an object or just taking its value?
Comment
Answer by mikelortega · Nov 19, 2015 at 03:27 PM
I think you should use Renderer.sharedMaterial instead of Renderer.material. The second one duplicates the material.
Your answer
Follow this Question
Related Questions
How do i change a color of an individual alphabet of a UI.Text 2 Answers
How to use structs in queues in C#? 1 Answer
Unity 2017 breaks scripts 0 Answers
There is a problem with my script... 0 Answers
Can somebody help me fix this script? 2 Answers