- Home /
Urgent help needed with changing objects texture on mouse click
Hi guys, I'm a total noob at JS and Unity but with help from this site I'm slowly getting there. I'm using the following code from another post to swap an objects material on mouse click. It works fine as is but when I have duplicates of the object (in my case a light switch that switches on and off) it effects all the light switches at once! I just need to effect one at a time. Here is the code I'm using:
var matArray : Material[];
private var index : int;
function Update () {
if (Input.GetButtonDown("Fire1")) {
index++;
index = index % matArray.Length;
renderer.material = matArray[index];
} }
One solution is to have an array of textures and ins$$anonymous$$d do:
render.material.mainTexture = texArray[index];
Your answer
Follow this Question
Related Questions
Texture-based mouseclick detection 1 Answer
Gui or texture (ex. circle) on plane by click 1 Answer
Video on an object. For example, a television. 1 Answer
Detect if object clicked on 2 Answers
Change Pickup key 1 Answer