- Home /
Change texture on click
Hello there. I have been trying to make an GameObject change it's texture by clicking it during the game. I made GameObject named "tile" which is located in materials/prefabs and it's texture already defined. Then I have 2 variables as 2D Textures. My code generates a grid of tiles, I'd like them to change their texture on click. How I can access the texture in the Tile object? How do I can make it respond when the GameObject tile is being clicked? I'd like the function to access it's texture and change it on click.
Answer by HarshadK · Dec 16, 2014 at 06:24 AM
renderer.material.mainTexture = texture;
OR
renderer.material.SetTexture("_MainTex", texture);
Read Input to learn about how to handle click events.
Your answer
Follow this Question
Related Questions
Reimporting during play changes UVs/Tiling? 0 Answers
Unity crashes when erasing tiles on a tilemap and entering those empty tiles. 0 Answers
Auto-tiling - adding tiles which are nearby the added one 0 Answers
Multiple random tiled textures in one material 1 Answer
Only Effect One Material? 1 Answer