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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -