- Home /
Question by
rsud · Jun 18, 2015 at 03:28 AM ·
gameobjecttexturesphere
assigning a texture to a GameObject
Seemingly simple question...
In my c# code I do:
public GameObject Sphere_meshGO;
public Texture sphereTex;
GOmesh = (GameObject) Instantiate (Sphere_meshGO, new Vector3 (0, 0, 0), Quaternion.identity);
How do I assign sphereTex texture to the GOmesh object I just created? I read that its dhould be:
GOmesh.renderer.material.mainTexture = sphereTex;
But this won't compile (.renderer does not resolve).
What's the code to assign a texture to GOmesh?
Comment
Best Answer
Answer by Eric5h5 · Jun 18, 2015 at 03:36 AM
Use GetComponent< Renderer >()
. There are no component accessor shortcuts anymore, except for Transform (since the Transform component always exists).
Your answer
![](https://koobas.hobune.stream/wayback/20220613201121im_/https://answers.unity.com/themes/thub/images/avi.jpg)