创建游戏对象的副本
在 Unity3D 中如何通过单击鼠标创建对象的副本?
另外,如何在运行时选择要克隆的对象? (最好选择鼠标)。
How do you create a copy of an object upon mouse click in Unity3D?
Also, how could I select the object to be cloned during run-time? (mouse selection preferable).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您会希望在多次调用 Update 的过程中发生这种情况:
And you'll want this to happen over course of many calls to Update:
最简单的方法(在 C# 中)是这样的:(
第一行只是确保对象上附加了一个碰撞器,需要检测鼠标单击)
该脚本应该按原样工作,但我还没有测试过还没有,如果没有的话我会修复它。
The simplest way (in c#) would be something like this:
(The first line just makes sure there is a collider attached to the object, it's required to detect the mouse click)
That script should work as is, but I haven't tested it yet, I'll fix it if it doesn't.
如果你的脚本附加到一个游戏对象(例如,一个球体),那么你可以这样做:
你给 Instantiate() 三个参数:什么对象,什么位置,它如何旋转。
该脚本的作用是在确切的位置和位置实例化某些内容。该脚本所附加的游戏对象的旋转。通常,您需要从游戏对象中删除对撞机,以及刚体(如果有)。实例化事物的方法有多种,因此,如果这个方法不适合您,我可以提供一个不同的示例。 :)
If your script is attached to a GameObject (say, a sphere), then you can do this:
You give Instantiate( ) three parameters: what object, what position, how is it rotated.
What this script does is it instantiates something at the exact position & rotation of the GameObject this script is attached to. Oftentimes you will need to remove the collider from the GameObject, and the rigidbody if there is one. There a variations in ways you can go about instantiating things, so if this one doesn't work for you I can provide a different example. : )