简体   繁体   English

如何在运行时加载播放器精灵。 统一

[英]How to load player sprite in runtime. Unity

I need to create sprites in runtime what you can move and animate not in unity editor. 我需要在运行时创建精灵,你可以移动和动画不在统一编辑器中。 How that is done? 怎么做? I'm lost here. 我迷失在这里。

Small question I know! 小问题我知道! Thanks for help :) 感谢帮助 :)

I've tried creating sprite first : 我先尝试过创建精灵:

    char_sprite = Resources.Load<Sprite>("Art/GamesPlusJames_RPG-Character_0");

Should I Instantiate it somehow to screen and how? 我应该以某种方式实例化屏幕以及如何实现?

Since you talked about creating, here is how you could do it 既然你谈到了创造,那么你就是这样做的

       //Create a new gameObject
        GameObject char_obj = new GameObject("char");
        //Add an SpriteRenderer component
        SpriteRenderer char_sprite = char_obj.AddComponent<SpriteRenderer>();
        //Load the sprite and assign it
        char_sprite.sprite = Resources.Load<Sprite>("Art/GamesPlusJames_RPG-Character_0");

If you only need to change the sprite. 如果你只需要更改精灵。 You can change it by accessing the SpriteRenderer component and change its sprite. 您可以通过访问SpriteRenderer组件并更改其精灵来更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM