今天是跟着b站up主学习unity的第一天,花了半个多小时学了一节课。课程链接在这里,是一套拼图类游戏的教程。
1.因为需要导入图片,所以引入了系统dll文件,可以直接在文件管理器搜索“forms.dll”即可找到。
image
2.在项目目录下新建个Plugins文件夹,再将dll文件复制到这个文件夹下,unity会自动生成文件。
image
3.创建一个空节点,然后把PuzzleManager脚本拖进去。
4.核心代码:
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "JPG|*.jpg|PNG图片|*.png";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string texPath = openFileDialog.FileName;
Texture2D tex2d = new Texture2D(1,1);
byte[] texByte = File.ReadAllBytes(texPath);
tex2d.LoadImage(texByte);
test.texture = tex2d;
}
}```