- Home /
Change Texture of Plane with script
Hi everyone, i need change texture of plane with script, i have a empty plane and i want add an image as texture, this will be dynamically ... thanks
Answer by Seth-Bergman · Mar 14, 2013 at 09:23 PM
simply use:
var myTexture : Texture;
then in your script:
renderer.material.mainTexture = myTexture;
this script would be attached to the plane itself.. to access the plane from another object, you would need to create a var for that:
var thePlane : GameObject;
then use in the code:
thePlane.renderer.material.mainTexture = myTexture;
this is the solution ...!!! now this work :) http://answers.unity3d.com/questions/14748/c-resourcesload-problem.html
Answer by eliascanaza · Mar 15, 2013 at 03:33 PM
I ... thnsk but this not work... so i tested with this code .... not work..
private Texture _texture;
void Start () {
_texture = Resources.Load("3-photo") as Texture;
renderer.material.mainTexture = _texture;
}
i have an image them i want load into plane
This code will work. $$anonymous$$ake sure the texture is in Assets/Resources. @Seth Bergman's original code will also work. You must drag and drop the texture you want onto the myTexture variable in the inspector for it to work.
not work, i have 5 images (texture) and a plane, when i clicked on button this plane will change an other texture
Answer by absolutegames · Mar 15, 2013 at 06:01 PM
Why is an answer with -2 votes above the answers with 0 votes?
Answer by zgamesoft · Jul 15, 2014 at 02:08 PM
Check this video https://www.youtube.com/watch?v=baFr-6Tafuc
Answer by akash_virodhia · Jun 17, 2017 at 12:52 PM
Simple C# code :
public Texture yourTexture ;
// then in the update function
GetComponent ().material.mainTexture = yourTexture;
Also, in higher version of unity 'renderer.material' is obsolete have to use 'GetComponent ().material' instead.
Your answer
Follow this Question
Related Questions
Change Texture of Plane with script 0 Answers
360 degree plane rotation & texture change 1 Answer
GUI Texture on Button Swap 3 Answers