Hi,
Is there a way to choose from a list of textures in an object using a string to choose it?
I have 10 textures that will be loaded into a script in the editor, and I want to choose one at any one time to be the current texture.
I try but get the error: Can not convert ‘String’ to ‘UnityEngine.Texture’
I have put my script below. I read in the Forum that I could put the textures in an array instead, but I have no Idea how to load textures into arrays. I think that would be more complicated than what I am trying here.
//this is a variable to receive a string from elsewhere
static var digit : String = "t0";
//will load a choice of 10 textures in editor
var t1 : Texture;
var t2 : Texture;
var t3 : Texture;
var t4 : Texture;
var t5 : Texture;
var t6 : Texture;
var t7 : Texture;
var t8 : Texture;
var t9 : Texture;
var t0 : Texture;
// currentTexure will be used to load that textue onto object
private var currentTexture : Texture;
function DigitDisplay () {
currentTexture = digit;
gameObject.renderer.material.mainTexture = currentTexture;
}
please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window. With a karma of 75, you should know this. Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
– AlucardJayThanks alucardj 59. Didn't know that. Much better...
– DFLY