Unity一些常用的小知识点笔记,WebGL部署报Unable to parse Build解决笔记 0 次阅读

Unity知识点一

Unity打包WebGL报Unable to parse Build

错误详情示例:

Unable to parse Build/*.framework.js.gz! This can happen if build compression was enabled but web server hosting the content was misconfigured to not serve the file with HTTP Response Header “Content-Encoding: gzip” present. Check browser Console and Devtools Network tab to debug.

图示:

unityError

解决办法

在Unity的WebGL创建时的PlayerSettings中,拉到最下面展开Publishing settings选项卡,把Decompression Fallback 选项勾上即可。

图示:

unitysetting

原因和原理

关于Decompression Fallback的unity官方的解释:

unityTip

参考翻译:在加载程序中包括生成文件的解压缩回退代码。如果无法根据选定的压缩方法配置服务器响应标头,请使用此选项。

Unity知识点二

一些常用的小知识

随机数生成

1
2
3

Random.Range(0, 10); //随机生成0到10之间的整数。不包含10

在指定位置生成物体/小怪/道具等

1
2
3

Instantiate<GameObject>(obj, position, Quaternion.identity);

obj : 要新建物体/小怪/道具的GameObject

position:生成的位置

2D角色转向

利用SpriteRenderer组件下的flipX属性

1
2
3

GetComponent<SpriteRenderer>().flipX = true;

或使用transform的localScale属性

1
2
3

transform.localScale = new Vector3(-1, 1, 1);

角色从一个点移动到另一点

1
2
3

transform.position = Vector3.MoveTowards(startPosition, endPosition, Time.deltaTime * speed);

计算两个点的距离

1
2
3

float dis = Vector3.Distance(startPosition, endPosition);

查找物体和子物体

1
2
3
4
5
6
7
8

//查找物体方法
GameObject go = GameObject.Find("Cube");

//查找子物体,并且将得到的物体转换成gameobject
GameObject objname = go.transform.FindChild("Sphere/Cylinder/Plane").gameObject;
Debug.Log("得到最终子物体的名字是:" + objname.name);

重新加载当前场景

1
2
3

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

加载下一个场景

需要先在构建项目前,在设置中把所有的场景一次拖入列表中,从上到下顺序排列。

1
2
3

SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);

结语

新的知识又又又增加了~

感谢阅读。

么么哒~~

上一篇 使用vercel和github免费实现serverless api接口服务部署
下一篇 修改JS数组中一个元素的值,其它元素也会跟着变化
感谢您的支持!
微信赞赏码 微信赞赏
支付宝赞赏码 支付宝赞赏