Unity WebGL 跨域访问CORS 头缺少 'Access-Control-Allow-Origin'
Unity WebGL的项目在编辑器下运行一切顺利,
然而
打包出来发现在浏览器里使用www或UnityWebRequest向服务器发送请求发现问题来了
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:54692' is therefore not allowed access.
主要因为跨域访问存在安全问题
目前已知解决办法
1.把项目放在服务器目录下
把IP地址删了,直接访问资源路径或方法
2.服务器方法加上 header("Access-Control-Allow-Origin: *");
这里使用的是php