Hey, I’ve only been using Unity for a couple of weeks and I’m just an artists making game assets and environments in the engine. In other words, I can’t script anything and I’ve been trying to figure out how to do a couple of simple environment interactions but I just don’t manage to get things working 
I’m hoping somehow could tell me how I can script the following:
I have a game object with a simple diffuse map. When the player hits or triggers a button, the object gets a different diffuse map. I want to use this in a showroom where the player can change the colors of the furniture.
If possible I would also like to know how I can do the same thing with game objects (instead of textures). By hitting a button an in-game model gets replaced by an other model.
Thanks in advance!
To change texture (attach this to the trigger):
var triggerTarget : GameObject; //model to change
var originalTex : Texture;
var replacementTex : Texture;
function OnTriggerEnter(other : Collider){
triggerTarget.renderer.material.mainTexture = replacementTex;
}
function OnTriggerExit(other : Collider){
triggerTarget.renderer.material.mainTexture = originalTex;
}
To change model (attach this to the trigger):
var triggerTarget : MeshFilter; //model to change
var originalModel : Mesh;
var replacementModel : Mesh;
function OnTriggerEnter(other : Collider){
triggerTarget.mesh = replacementModel;
}
function OnTriggerExit(other : Collider){
triggerTarget.mesh = originalModel;
}
EDIT: I haven’t tested these.
Thanks sccrstud92! 
I’ve added the script to a trigger, linked the right model and textures but it still doesn’t seem to work. Did I do something wrong or could it be the script?
Does the compiler generate errors or does it just not work?
If there are errors, please post them here. If it just doesn’t work, then what does happen exactly?
Nope no errors, so I guess it’s probably something I did wrong?
I can just run the game, I hit the trigger but nothing happens
Which script are you trying where nothing happens?
Does the thing entering the trigger have a rigidbody attached?
No, I dont think it has, does it have to?
I’m using the standard First Person Controller
I think that should work.
To see if the trigger is triggering, add the line
Debug.Log('triggered!");
to the OnTriggerEnter function. If you the the word “triggered!” in the console, then the trigger works and the code in the trigger works incorrectly. If you don’t see it, then there is a problem with the trigger set up.
Yeah, I hit the trigger and I get “triggerd!” in the console, while my trigger target(model) doesn’t change its OriginalTex with the ReplaceTex, so nothing visible changes. So this means the code in the trigger doesn’t work?
The trigger is working, which is good. However, if the script is still not working, then there is a problem somewhere else. Are you sure, that you set the triggerTarget, replacementTex, and originalTex in the inspector?
This is really strange. A simple script like this shouldn’t be making so much trouble. Anyone else have some ideas for this?
I actually just did this.
I edited it to take my gamelogic out but hope it helps.
You need to drag the texture you want to change to into the editor.
edit: i just attached this script to the object i wanted to change texture of.
var texture1 : Texture2D;
var isTriggered = false;
function OnTriggerEnter (col : Collider) {
Debug.Log("triggering");
isTriggered = true;
}
function OnTriggerExit (col : Collider) {
Debug.Log("triggering exit");
//isTriggered = false; I used this to change it back on exit as it suited my game
}
function Update () {
if(isTriggered)
{
rend = gameObject.GetComponent(Renderer);
rend.material.mainTexture = texture1;
}
}
Ok, I got the last script from TheRaider to work. I also tried to understand both scripts (from TheRaider and sccrstud92) in order to understand what it did exactly. I learned a lot already, thanks guys!
Now I only have to figure out how to make the last script work with another object being the trigger instead of the main object itself.
What do you mean by that?
I essentially used that on a whole group of sensor plates to change textures to visually show they had been stepped on. You should be able to attach it to any object and if your controller triggers it will excute the script.
Glad I could help someone instead of being the one needing help!
In mine you could actually take what is in the update function and put it in the onTiggerEnter and not need the boolean. I just set it up that way because of extra game logic as I was keeping track of things like if you were allowed to trigger it, keeping count etc.
I mean that I want a button to act as a trigger that changes the texture of another object (and not the texture of the button itself), similar to what sccrstud92’s script was supposed to do 
oh okay just use GameObject.Find(“Name here”).GetComponent(Renderer) instead of GameObject.GetComponent(Renderer)
or you might have to do it in a 2 line step. First find the object and set it to a variable then getComponent.
I think that would work. I can’t check now, but that is the approach i would take.
It finally worked, thanks a lot! ^^ Didn’t have to do it in a 2 line step either. I’ll post the result soon 
Thanks again!