- Home /
Texture2D Count C#
public List<Texture2D> textureList;
void OnGUI(){
if(GUI.Button(new Rect(10,10,200,50),"White")){
renderer.material.mainTexture = textureList[0];
for(int i=0; i<textureList.Count;i++){
//a = 0
int a = textureList[i];
Debug.Log(a);
}
}
if(GUI.Button(new Rect(10,60,200,50),"Blue")){
renderer.material.mainTexture = textureList[1];
for(int i=0; i<textureList.Count;i++){
//a = 1
int a = textureList[i];
Debug.Log(a);
}
}
}
error CS0029: Cannot implicitly convert type UnityEngine.Texture2D' to
int'
What is wrong? How can do it?
I want to access active texture number. Like this: Debug.Log ("Active texture no:" + XX)
Can you explain what are you trying to achieve? You can debug the texture name if you want. Can you give more information?
I handle it this way:
public List<Texture2D> textureList;
int textureCount;
if(GUI.Button(new Rect(10,10,200,50),"White")){
textureCount=0;
changeColor();
}
void changeColor(){
renderer.material.mainTexture = textureList[textureCount];
PlayerPrefs.SetInt ("COLOR",textureCount);
}
=))
Answer by Priyanshu · Jan 07, 2015 at 11:17 AM
a is type of integer and textureList is type of Texture2D
Hence the error
renderer.material.mainTexture = textureList[0];
Activate texture number is 0.
renderer.material.mainTexture = textureList[1];
Active texture number is 1.
Your answer

Follow this Question
Related Questions
Create Texture2D and assign image to it through a script 1 Answer
Two flat textures interfere with each other when both on z=0 2 Answers
How do you create animated textures with Texture2D.Apply with any regularity? 1 Answer
Reloading texture2d from code 1 Answer
Unlit/Transparent texture leaves dark lines on the transparent edges 1 Answer