Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一从资源文件夹将精灵加载到游戏对象_C#_Unity3d - Fatal编程技术网

C# 统一从资源文件夹将精灵加载到游戏对象

C# 统一从资源文件夹将精灵加载到游戏对象,c#,unity3d,C#,Unity3d,我是新来的。我在这个地址有一个简单的精灵: Assets <- (Folder) | - Block <- (Block is a PNG file that dragged to unity project widget) Assets它不适合您,因为它需要放在名为Resources的文件夹中,如Assets/Resources/Block.png 然而:根本没有! 只需将文件保持原样,并将其拖动到Inspector中的Sprite字段中即可。如果您确实需要在运行时执行,那么

我是新来的。我在这个地址有一个简单的精灵:

Assets <- (Folder)
|
 - Block <- (Block is a PNG file that dragged to unity project widget)

Assets它不适合您,因为它需要放在名为
Resources
的文件夹中,如
Assets/Resources/Block.png


然而:根本没有! 只需将文件保持原样,并将其拖动到Inspector中的
Sprite
字段中即可。如果您确实需要在运行时执行,那么请确保执行代码的组件具有相应的字段,例如

//通过Inspector从此处的资源中拖动精灵
[SerializeField]专用精灵块;
私有方法()
{
var renderer=新游戏对象(“B1”).AddComponent();
renderer.sprite=块;
renderer.flipX=true;
}


另外,如果你是Unity的新手,你不应该从遗留版本开始。使用最新的稳定版本
2019.3.4f1
,或者使用长期支持的
2018.4 LTS
(尽管很快就会有新的LTS版本
2019.4

@Shamshirsaz.Navid Gladd来帮助您!如前所述,不要使用它!我真的推荐第二个解决方案-请看链接我检查了它谢谢:)但另一个问题;如果我仍然在android游戏中使用unity 5,我可以稍后迁移到2019版吗?@Shamshirsaz.Navid不太可能没有任何问题。。同时发生了很多变化!
Sprite block = Resources.Load<Sprite>( "Block" );
GameObject obj = new GameObject ("B1");
SpriteRenderer renderer = obj.AddComponent<SpriteRenderer> ();
obj.GetComponent<SpriteRenderer> ().sprite = block;
obj.GetComponent<SpriteRenderer> ().flipX = true;