Hey Guys,
I am trying to make a menu that scrolls across the screen by changing the texture of the image when it goes off the screen and then making it appear on the other side, so it looks like there are a lot of items.
Here is the texture switching code:
var Lesson1Tex : Texture;
var Lesson2Tex : Texture;
var Lesson3Tex : Texture;
var Lesson4Tex : Texture;
var Lesson5Tex : Texture;
var Lesson6Tex : Texture;
var Lesson7Tex : Texture;
var Lesson8Tex : Texture;
var ExitTex : Texture;
var num = 1;
function SwitchTexture () {
switch (num) {
case 1 : renderer.material.mainTexture = Lesson1Tex;
case 2 : renderer.material.mainTexture = Lesson2Tex;
case 3 : renderer.material.mainTexture = Lesson3Tex;
case 4 : renderer.material.mainTexture = Lesson4Tex;
case 5 : renderer.material.mainTexture = Lesson5Tex;
case 6 : renderer.material.mainTexture = Lesson6Tex;
case 7 : renderer.material.mainTexture = Lesson7Tex;
case 8 : renderer.material.mainTexture = Lesson8Tex;
case 9 : renderer.material.mainTexture = ExitTex;
}
}
I do not get any error messages, but it does not work.
Can anyone help?
AGhost
Is SwitchTexture() being called? If you put a Debug.Log() in it do you get output. If so, what is the value of num? Also, do you need the “break” statement for each case and the “default:” case in there?
If SwitchTexture() is getting called, then I imagine that the texture is always being set to ExitTex. As lfrog pointed out, you need break statements in there:
switch (num) {
case 1:
renderer.material.mainTexture = Lesson1Tex;
break;
case 2:
renderer.material.mainTexture = Lesson2Tex;
break;
case 3:
renderer.material.mainTexture = Lesson3Tex;
break;
case 4:
renderer.material.mainTexture = Lesson4Tex;
break;
case 5:
renderer.material.mainTexture = Lesson5Tex;
break;
case 6:
renderer.material.mainTexture = Lesson6Tex;
break;
case 7:
renderer.material.mainTexture = Lesson7Tex;
break;
case 8:
renderer.material.mainTexture = Lesson8Tex;
break;
case 9:
renderer.material.mainTexture = ExitTex;
break;
}
You may want to add a default case to that as a fall through, but it is not strictly necessary.
...
case 9:
renderer.material.mainTexture = ExitTex;
break;
default:
renderer.material.mainTexture = ExitTex;
break;
}
I would suggest using an array of textures instead of a clumsy switch statement and multiple variables. Also note the comments added below:
var lessonTextures : Texture[];
var num = 1; // Where is this number incremented?
function SwitchTexture () { // When is SwitchTexture called?
renderer.material.mainTexture= lessonTextures[num];
}
Thanks for the help.
As for where it is called and incremented, the script itself is 500+ lines so I didn’t want to paste the whole thing. Also I found that my system didn’t work so I rewrote the whole thing.
Thanks All!