unity3d - Unity Resources.Load<Sprite> vs as Sprite -
i've tried change image of object code (used as sprite cast):
getcomponent<spriterenderer>().sprite = resources.load("gameobjects/tiles/hole") sprite;
it did not work, worked (used <sprite>):
getcomponent<spriterenderer>().sprite = resources.load<sprite>("gameobjects/tiles/hole");
what's difference?
resources.load("gameobjects/tiles/hole") sprite;
you have "hole" in resources folder. other-hole not sprite
. therefore when use as sprite
can't casted 1 , won't throw exception (on line) because:
the operator cast operation. however, if conversion isn't possible, returns null instead of raising exception.
resources.load<sprite>("gameobjects/tiles/hole");
in working code specify file want, sprite
, finds correct one.
Comments
Post a Comment