cannot cast from source type?
I have a 3d model,and I want to change it’s skin .
here is my code.
renderer.material.SetTexture(“_BumpMap”, Resources.Load(“Normal_1024”,Texture2D));//work
renderer.material.mainTexture= Resources.Load(“KH6025_1024”,Texture2D); //can’t work. throught an error :invalidcastExcetion:cannot form source type to destiontion.
How can I do to fixed this error?
In C#:-
renderer.material.mainTexture= (Texture2D) Resources.Load("KH6025_1024",Texture2D);
In JS:-
renderer.material.mainTexture= Resources.Load("KH6025_1024",Texture2D) as Texture2D;
There are no explicit cast operators in Unity’s Javascript. Both of those examples would work in C#, but not in Javascript. Instead, you need to cast implicitly:
var loadedTexture : Texture2D = Resources.Load("KH6025_1024",Texture2D);
renderer.material.mainTexture = loadedTexture;
Have I just completely misunderstood what the “as” operator is for in Unity JS?