#pragma strict
var textureM : Texture;
var textureS : Texture;
var textureD : Texture;
var textureC : Texture;
function Update () {
//MOVEMENT
if(Input.GetKey("left")) {
transform.Rotate(0,180*Time.deltaTime,0);
}
else if(Input.GetKey("right")) {
transform.Rotate(0,-180*Time.deltaTime,0);
}
//END MOVEMENT
if (Input.GetKey (KeyCode.Q))
renderer.material.mainTexture = textureM;
if (Input.GetKey (KeyCode.W))
renderer.material.mainTexture = textureS;
if (Input.GetKey (KeyCode.E))
renderer.material.mainTexture = textureD;
if (Input.GetKey (KeyCode.R))
renderer.material.mainTexture = textureC;
}
this script is in the inspector of the gameObject
When I press Play and press Q W E or R, Unity change the texture ONLY in the Inspector, but not for the Object in the scene.
I don’t understand how you can see a change in the inspector but not see it in the game view.
You have applied a different texture for each of your texture variables?
What we are interested here is the material under Mesh Renderer, and as can be seen from your screenshot it hasn’t changed from matrix.
Instead of changing the texture of the material, have you tried creating 4 different materials, and in the script change the material of the renderer instead of the material.maintexture?
Oh, huh, that’s so weird. I can’t see anything wrong with that code, but can you check with Debug.Log if those conditions actually pass?
I’ll also give this a try at home in a few hours and see what’s up.
I don’t know what’s going on. I tried your code at home with two materials and works fine for me. Is there anything special about the materials you are using? Why does it say (Instance) on them?
I tried with others materials, just for see if the problem is in the materials/textures used.
The (Instance) don’t appears but the problem is the same.
EDIT:
ok, I tried to create a standard cube. Well the script runs perfect…so the problem is my object?
I import him from 3ds Max
OK maybe I found a solution.
My object is a composition of a mesh and a bone (for the movement).
If I apply the script direct to the mesh it works! but not the rotation
so I have to split the script in 2.
One part for the movement to assign at the all object
One part for the material to assign to the mesh inside the object.