Unity 在对象脚本之间共享布尔值
我试图创造一个谜题,将一个盒子移动到压力板上时会打开一扇门。当我将盒子放在压力板上时,我试图将布尔值传递给大门,告诉它打开。这是实现我的目标的正确方法吗?
我有 Unity 版本 3.4,它不是专业版,我正在使用 C# 进行编码。
任何帮助都很感激,因为我刚刚开始尝试学习团结。
I was trying to create a puzzle where a box when moved onto a pressure plate opens a gate. When I get the box onto the pressure plate I was trying to pass a Boolean to the gate telling it to open. Is this the correct way of achieving my goals?
I have unity version 3.4 it is not pro and i'm coding in C#.
Any help appreciated as I have just started trying to learn unity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的门游戏对象在层次结构视图中的名称为 MagicGate,并且分配了一个 GateController 类型的脚本组件,其中包含以下代码:
可能还有另一个类 GameStatusController,您可以在其中检测到盒子位于魔法压力板处(碰撞器对此很有用)。在那里你可以:
Let's say your gate game object has the name MagicGate in your hierarchy view and has a script component assigned of type GateController containing the following code:
There is another class maybe GameStatusController where you detect that the box is at the magic pressure plate (Colliders are useful for this). There you do: