Search code examples
unity-game-engine2dlayerunity3d-2dtools

Unity 2D use clones as independent gameobjects


I'm making a 2D Unity game, in which you can move over 3 lanes and fire arrows that only affects their specific lane.

In order to do that I'm changing the layer of the arrow prefab every time you move from one lane to another.

Arrows change to children of the terrain on hit, but when the arrow prefab change his layer, clone arrows do the same(even the ones that are parented to terrain in other lane)

How can I make arrows that are parented to terrain not to be affected by the arrow prefab change of layer?

Thanks


Solution

  • You say you're changing the prefab layer, if that's correct, you're basically changing every clone made from that prefab. If you want to change each lane's arrows by themselves, you should change the clones directly, not the prefab.

    Maybe you could add 3 lists of arrows, one for each lane, and each time you fire an arrow, have it added to its list. Then you can iterate over that list changing every GameObject layer.