简体   繁体   English

有没有办法区分统一的克隆

[英]Is there a way to distinguish between clones in unity

I am developing a game in unity, the main thing in the game is a tower. 我正在开发一个统一的游戏,游戏中的主要内容是塔。
The tower is built of 1000 Cubes. 该塔由1000立方体建造。 Each time that the player's shot hits the tower, it moves 1 unit down in the y axis. 每次玩家的射击击中塔时,它会在y轴上向下移动1个单位。

I want to improve performance by making only the first 30 gameObjects (the first 30 cubes) Active and the rest Not Active. 我想通过只使前30个gameObjects(前30个立方体)Active和其余Not Active来提高性能。

How can I distinguish between the first 30 cubes and the rest because I don't know anything about the Not Active objects (After I make it Not Active the script on them is Not Active either and can not send information about each one of the clones). 如何区分前30个立方体和其余部分,因为我对Not Active对象一无所知(在我将其设置为非活动状态后,它们上的脚本也处于非活动状态,并且无法发送有关每个克隆的信息)。

I already tried to instantiate each cube after a certain y the tower hits but it was a problem because the tower is rotating and I can not instantiate exactly where the cubes are supposed to be. 我已经尝试在塔撞到一定数量之后实例化每个立方体,但这是一个问题,因为塔正在旋转,我无法确切地实例化立方体应该在哪里。

I'm not completely sure about what are you asking for, but I would suggest you to remove script attachment with every cube and make empty game object called something like Event Handler . 我不完全确定你要求的是什么,但我建议你删除每个立方体的脚本附件,并制作一个名为Event Handler之类的空游戏对象。

Method 1 方法1

Then you can refactor your code to move inactive cubes within script attached to this empty object. 然后,您可以重构代码以在附加到此空对象的脚本中移动非活动多维数据集。 You will find inactive cubes using Resources.FindObjectsOfTypeAll() . 您将使用Resources.FindObjectsOfTypeAll()找到非活动的多维数据集。

Method 2 方法2

Before setting off your cube (making it inactive) simply make a reference to it. 在设置多维数据集(使其处于非活动状态)之前,只需引用它即可。 Save all those cubes in some kind of list/array or something. 将所有这些立方体保存在某种列表/数组或其他内容中。

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

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