Unity3D:基于当前位置产卵对象 - 将在画布上在同一位置 [英] Unity3D: Spawning an object based on current position - putting onto canvas in same position

查看:519
本文介绍了Unity3D:基于当前位置产卵对象 - 将在画布上在同一位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,当它被摧毁它会给你留下的后面。

I have an object which when it is destroyed it will leave something behind.

//Spawn object at point
GameObject bonusDrop = (GameObject)Instantiate(bonusItem,target.transform.position, Quaternion.identity);

//Set the transform to the canvas (without this line the position is correct)
bonusDrop.transform.SetParent(canvas.transform);

//object is completely off




  • 我想将其设置为画布,因为它的目的是作为一个UI元素

  • 对象在正确的位置,如果我不设置父结束(但如果我不设置父UI元素将无法工作按预期)。

  • 我喜欢一些帮助在试图弄清楚这一点。我讨厌这样说,但我觉得解决方法很简单,我不能让它=(

  • 推荐答案

    退房: http://docs.unity3d.com/ScriptReference/Transform。 SetParent.html

    您有与世界空间VS局部空间的问题。你的游戏物体bonusDrop,设置它的父面前,存在于全球太空也就是说其变换是基于(0,0)的全局原点。

    You are having an issue with world space vs local space. Your GameObject bonusDrop, before setting its parent, exists in global space meaning that its transform is based on the global origin of (0,0).

    当您设置的父母,你的bonusDrop游戏物体变换成为当地父游戏对象的变换。

    When you set the parent, your bonusDrop GameObject transform becomes local to the parent GameObject's transform.

    这意味着,bonusDrop的变换是看着父母转化为原点。

    This means that bonusDrop's transform is looking at the parents transform as the origin.

    函数调用setParent()具有第二参数,它可以帮你出了这个问题。

    The function SetParent() has a second parameter which may help you out with this issue.

    如果您仍然有问题,然后让我知道。

    If you still have trouble, then let me know.

    这篇关于Unity3D:基于当前位置产卵对象 - 将在画布上在同一位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆