- Home /
Texture offset problem.
how to instantiate a gameobject in unity with a material attached to it with same texture but different offset setting. Am generating a bunch of game object from a single prefab with same texture but different offset. My problem when i change the offset or one other game object offset also get change.
Answer by Fattie · Mar 18, 2013 at 12:03 PM
Use code like this for your Pool,
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
look at line 38 of the code where you set the name of the pool item
directly after that, just set the offset, using "newy"
So something like
newy.renderer.material. SetTextureOffset ...
Read this doco
http://docs.unity3d.com/Documentation/ScriptReference/Renderer-material.html?from=Material
"Modifying material will change the material for this object only. If the material is used by any other renderers, this will clone the shared material and start using it from now on. Important note: This function automatically instantiates the materials and makes them unique to this renderer."
Further ... memory management ..
Note that if you are programming in a sophisticated manner, then: "It is your responsibility to destroy the materials when the game object is being destroyed. Resources. UnloadUnusedAssets also destroys the materials but it is usually only called when loading a new level." Generally you won't have to worry about that but bear it in mind if you have a highly dynamic game.
hope it helps
it's nothing, any time - ask away
Do me a favour if you like and
http://answers.unity3d.com/questions/321762/how-to-assign-variable-to-a-prefabs-child.html
vote Up my long answer there - I am desperate for a 25 score answer! Two to go! :)
thanks...
Your answer
![](https://koobas.hobune.stream/wayback/20220613094626im_/https://answers.unity.com/themes/thub/images/avi.jpg)