问题标签 [unity3d]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3822 浏览

user-interface - 如何加载随机关卡?

我正在使用 Unity 3 构建我的游戏。我有一个基本的 GUI 按钮,单击该按钮时,我希望将用户带到一个随机级别。我的游戏有 10 个关卡。下面是我正在尝试实现的代码的副本。

它没有发生。我也试过:

我以前从未使用过 Random.Range 函数,并且对正确的格式有些困惑。

我也有可用的 EZ GUI,想知道是否可以在“脚本”下拉菜单或“带有方法的脚本”下拉菜单中输入正确的随机范围脚本,因为我宁愿使用自定义按钮。任何帮助将不胜感激。

0 投票
1 回答
9121 浏览

c# - 使用 LitJson 在 C# 中反序列化 JSON 对象数组

我受到 Unity3d 3 新安全措施的限制,无法将 LitJson 用于 Web Player 应用程序,否则将无法编译。

有没有一种简单的方法可以将此输出序列化为对象(userEcoGet.text 的内容):

此代码仅从 JSON 输入第一个对象:

将 localEcoData 转换为数组会导致缺少构造函数错误。而且我只是不知道如何在这种情况下正确嵌套构造函数,甚至不确定它是否会有所帮助。

在这一点上,我求助于使用 JsonReader 并手动填写对象。任何帮助,将不胜感激。谢谢你。

编辑:这太疯狂了,今天一整天都因为我对自己造成的糟糕的 JSON 格式而被杀死......

现在完美运行,localEcoData[1,2...32] 是一个对象数组,所有元素均可访问:

我所要做的就是在处理 MySql 的 PHP 页面上正确编写 JSON 并以有序的方式传输回 Unity。我直接回显而不使用数组进行传输。现在输出看起来像这样并且效果很好:

谢啦!

0 投票
1 回答
1693 浏览

c# - iPhone System.IO.File.Exists() 不工作

以下指令检查路径中的文件是否存在:

然后,如果该文件不存在,它会创建一个新文件,它在统一执行中运行良好,但是当我在 iphone 中执行该程序时,该文件永远不会创建。

下面是获取路径的函数:

0 投票
3 回答
3278 浏览

scripting - Unity 3D 物理

我在统一 3d 中遇到物理问题。我希望我的球从墙上弹回并朝另一个方向移动。当球撞到墙上时,它会直接弹回来。我尝试将方向更改为与它撞墙的方向正交,但它不会改变方向。因此,球只会不断地撞到墙上并直接弹回。

其次,有时球会穿过墙壁。墙壁有盒子对撞机,而球有球对撞机。它们都具有连续动态作为碰撞检测模式。

0 投票
11 回答
126668 浏览

unity3d - 使用Unity开发用什么语言

使用 Unity 编程时需要使用什么语言?还是它是多种语言的 API?

我通读了文档,我想我错过了所用语言的要点。

它说它有 iOS 部署,这仍然允许程序员在目标 C 中编码吗?

Unity 是一个可用于许多平台的 sdk 还是它是如何工作的?它提到在多个平台上部署相同的代码。

0 投票
2 回答
386 浏览

unity3d - Detection of userAgents that do/do not support Unity3d Plugin

The unity3d web player plugin is supported by Explorer, Firefox, Safari, Mozilla, Netscape, and Camino on Windows or OSX.

Via JavaScript, what is the best method for determining whether a users configuration is supported, so I can alert them with the appropriate message? Is there a plugin out there that might support this case well? I'm looking for an easier solution than combing through the properties manually and testing on different devices myself.

Thanks in advance!

0 投票
5 回答
8602 浏览

c# - 使用 Java/C#(包括 XNA)/Unity 开发游戏的原因是什么?

我正在考虑创建一个游戏只是为了好玩。用这些语言编程有什么优势?
我相信 Unity 和 Java 都有自己的可嵌入小程序,而 C# 有一个软件包(XNA Game Studio),可以为 Windows Phone、XBOX 360 和 PC 开发游戏。

只是一些标准:

  • 语言的平台兼容性如何(可以在 Mac 上运行吗,我希望它绝对可以在 PC 上运行)
  • 它是否有用于游戏开发的库(请包括这些)?
  • 运行时的基本性能如何?(经常发生崩溃吗?)
  • 它可以在网络浏览器中运行吗?
  • 用户是否必须安装运行时?
  • 任何其他使语言变得好的东西......

我想为PC开发游戏。

0 投票
2 回答
2426 浏览

math - Generating a 3D prism from any 2D polygon

I am creating a 2D sprite game in Unity, which is a 3D game development environment. I have constrained all translation of objects to the XY-plane and rotation to the Z-axis.

My problem is that the meshes that are used to detect collisions between objects must still be in 3D. I have the need to detect collisions between the player object (a capsule collider) and a sprite (that has its collision volume defined by a polygonal prism).

I am currently writing the level editor and I have the need to let the user define the collision area for any given tile. In the image below the user clicks the points P1, P2, P3, P4 in that order.

enter image description here

Obviously the points join up to form a quadrilateral. This is the collision area I want, however I must then convert that to a 3D mesh. Basically I need to generate an extrusion of the polygon, then assign the vertex winding and triangles etc. The vertex positions is not a problem to figure out as it is merely a translation of the polygon down the z-axis.

enter image description here

I am having trouble creating an algorithm for assigning the winding order of the vertices, especially since the mesh must consist only of triangles.

Obviously the structure I have illustrated is not important, the polygon may be any 2d shape and will always need to form a prism. Does anyone know any methods for this?

Thank you all very much for your time.

0 投票
2 回答
4051 浏览

c# - C# Mono aot 与 protobuf-net 获取 ExecutionEngineException

首先非常感谢 protobuf-net http://code.google.com/p/protobuf-net/的作者 Marc Gravell 。这真是一个很棒的资源。无论如何,我希望 Marc 或其他人可以帮助我解决这个异常。

我正在尝试使用 Unity3D 游戏引擎在移动设备(iOS 和 Android)上实现 protobuf-net。Unity 3.2 使用 Mono 2.6,这是对 mono 的略微修改版本。

它在编辑器中运行良好,但在 iOS 设备上运行时它在它尝试序列化的第一个成员处失败。请注意异常中的 --aot-only 标志。我认为 Unity 基本上是通过 Mono 的 aot 功能构建 ARM 程序集,尽管我不明白它在后台做什么。

IRC 上有人建议我可以提前声明这些类型的变量,编译器不必在运行时对它们进行 JIT。似乎是个好主意,但不幸的是,这些就像内部泛型类型,并且不知道在 C# 中编写什么来声明变量以伪造编译器。任何人都可以解释上述消息并让我知道编译器需要提前知道什么吗?还有其他防止这种情况发生的策略吗?顺便说一句,这是错误的类的顶部

感谢 Mono 和 protobuf 专家帮助我解决这个问题!protobuf-net 似乎是一个很棒的轻量级序列化和 RPC 有线协议,非常适合 iOS 和 Android 应用程序,所以我期待使用它。

0 投票
1 回答
1749 浏览

c# - 二维距离约束

我一直在尽一切努力让 2D 距离关节在 Unity 中工作。我希望通过关节和连接的身体自由旋转,我还需要遵守质量和其他约束,例如固定刚体的位置。我已经尝试了好几天,配置任何关节类型都没有运气。使用以下方法尝试了一个 verlet 约束:

但这没有考虑质量/力或任何固定装置。你可以在这里看到我想在 X/Y 上移动,只在 Z 上旋转。

帮助?