- Home /
texture change problem
var cubeToggle : boolean = false; var window1 : Rect = Rect (20,20,650,300); var cube3 : Transform; var cube4 : Transform; var texture1 : Texture2D; var texture2 : Texture2D; function OnGUI() { window1 = GUI.Window(0,window1,firstwindow,"LOGIN WINDOW"); if(table9 == true) { cubeToggle = GUI.Toggle(Rect(Screen.width*(4.5/6.55),Screen.height*(4/6.3),Screen.width* (1.7/6.55),Screen.height*(1/6.3)),cubeToggle,"CUBE1"); cubeToggle = !GUI.Toggle(Rect(Screen.width*(4.5/6.55),Screen.height*(4.25/6.3),Screen.width*(1.7/6.55),Screen.height*(1/6.3)),!cubeToggle,"CUBE2"); }
}
function firstwindow(windowID : int) {
if(table7 == true)
{
GUI.Label(Rect(200, 250, 300, 100), "YOU HAVE CLICKED ON:cube1 ");
}
if (table8 == true)
{
GUI.Label(Rect(200, 250, 300, 100), "YOU HAVE CLICKED ON:cube2 ");
}
if (cubeToggle == true)
{
table7 = true;
cube1.renderer.material.mainTexture = texture1;
}
if(!cubeToggle == true)
{
table8 = true;
cube2.renderer.material.mainTexture = texture2;
cubeToggle = false;
}
}
Here my problem is: I have two cubes (cube3 and cube4) with two toggle buttons (cube 1 and cube2) My need is when I click on cube1, toggle button texture should change to texture1; and when I click on cube2, toggle button texture should change to texture2. When cube1 toggle button is clicked, corresponing label should display "you have clicked on cube 1". When cube2 toggle button is clicked, corresponing label should display "you have clicked on cube 2"
I'm not a very experienced programmer and I haven't looked into changing textures etc. but I do know that changing material (which would do pretty much the exactly same thing as long as the materials are identical apart from their name and the texture they're using.) work since I've done it that way myself once. :)
Answer by DaveA · Feb 16, 2011 at 09:14 PM
Do you need to handle both cubes in the same script? I would have a script that just changes one thing, and put it on both cubes.
i want both cube when first toggle button pressed then texture of first cube should change when second toggle is pressed second cube texture should change that is my sample code
Your answer
Follow this Question
Related Questions
How to render part of an object 2 Answers
How can I change an object's texture in-game when the object is unlit? 2 Answers
How to: Create shader and copy texture? 2 Answers
Changing texture for pause button 1 Answer
Changing GameObject texture? 4 Answers