- Home /
C# WWW texture and webplayer
I have a JS code that works when I used it in winwebplayer
function setupTexture(){
var mats = GetComponent.<Renderer>().materials;
var clientPath : String;
if(Application.platform == RuntimePlatform.WindowsWebPlayer){
clientPath = Application.dataPath;
} else {
clientPath = "file://" + Application.dataPath;
}
var Skin : WWW = new WWW (clientPath + "/TextureArray/01Skin/test.png");
var Feet : WWW = new WWW (clientPath + "/TextureArray/02Shoes/test.png");
var Legs : WWW = new WWW (clientPath + "/TextureArray/03Pants/test.png");
yield Skin;
yield Feet;
yield Legs;
mats[0].mainTexture = Skin.texture;
mats[1].mainTexture = Feet.texture;
mats[2].mainTexture = Legs.texture;
mats[2].color = new Color(Random.Range(0f,1f) ,Random.Range(0f,1f),Random.Range(0f,1f),1f);
GetComponent.<Renderer>().materials = mats;
}
I have tried to convert it to C# but I can not get it to work in the webplayer
// private IEnumerator setupTexture(){
private void setupTexture(){
Material[] mats = this.gameObject.GetComponent<Renderer>().materials;
string clientPath;
if(Application.platform == RuntimePlatform.WindowsWebPlayer){
clientPath = Application.dataPath;
} else {
clientPath = "file://" + Application.dataPath;
}
WWW Skin = new WWW (clientPath + "/TextureArray/01Skin/test.png");
WWW Feet = new WWW (clientPath + "/TextureArray/02Shoes/test.png");
WWW Legs = new WWW (clientPath + "/TextureArray/03Pants/test.png");
// yield return Skin;
// yield return Feet;
// yield return Legs;
mats[0].mainTexture = Skin.texture;
mats[1].mainTexture = Feet.texture;
mats[2].mainTexture = Legs.texture;
mats[2].color = new Color(Random.Range(0f,1f) ,Random.Range(0f,1f),Random.Range(0f,1f),1f);
this.gameObject.GetComponent<Renderer>().materials = mats;
}
I tried with and w/o the yield in c#. As is, it works in the editor and in a winClient Anyone that can point me in the direction of what I am doing wrong in relation to the webclient.
[EDIT] >> The code loads 3 png files and put them onto model. when I use the C# version in the webplayer no textures are loaded but no error about unfound paths are shown either. when run' from a winexeclient the textures are loaded. [EDIT] <<
Note. I do not fully understand what yield does so it might be that I use it wrong?
(This is just a small program to quickly test out textures) Skill level: hobbyist
Comment
Your answer
