简体   繁体   English

在C#中以统一3D方式使对象成为子对象

[英]Make into child of a object in unity 3d in c#

My code is here 我的代码在这里

GameObject mainpumkinclone = (GameObject)Instantiate(pumkin, 
floorPosition + new Vector3(x, y, z), Quaternion.identity);
mainpumkinclone.transform.parent = transform.Find("prickle" + i);

But mainpumkincloneis not become a child of a specific prickle. 但是mainpumkincloneis不会成为特定的刺痒的孩子。

Please help to solve this issue. 请帮助解决此问题。

thanks in advance. 提前致谢。

Is GameObject "prickle" named like that in the Editor? GameObject的“刺客”是否在编辑器中这样命名? Is ia number that would match that game object? 是与该游戏对象匹配的数字吗? For example, "prickle1" is a GameObject in the Editor scene. 例如,“ prickle1”是编辑器场景中的GameObject。 If the answer is yes to both of these then try this. 如果对这两个答案都是肯定的,请尝试此操作。

mainpumpkinclone.transform.parent = GameObject.Find("prickle" + i).transform;

As you can see from the Unity script reference page on Transform , that class has no function Find . TransformUnity脚本参考页可以看到,该类没有功能Find To find an object by name, as you are trying to do, you need to use the class function Find of the class GameObject , as documented here . 按名称找对象,因为你正在尝试做的,你需要使用类函数Find类的GameObject ,如记录在这里 Then you assign that game object's transform (using its transform property ) as the parent of your other game object. 然后,您将该游戏对象的转换(使用其transform属性 )分配为其他游戏对象的父对象。 Specifically, do this: 具体而言,请执行以下操作:

mainpumpkinclone.transform.parent = GameObject.Find("prickle" + i).transform

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM