I’m creating a game that uses clouds and lightning. The clouds are moving across the screen left or right respectively. When I instantiate the lightning, it destroy itself immediately. The lightning is a child of the cloud, but the cloud keeps moving and the lightning looks off center when it spawns because the cloud continues on.
Is there a way to hinge or keep the lightning object moving with the cloud?
In the attached image you’ll see the lightning graphic is offset, it needs to stay centered on the cloud.

In order to diagnose the issue with your code instantiating the lightning, we would have to see your code.
However, I think you’ll be better off not instantiating lightning at all. Leave the lightning there and a child of the cloud, and just activate/deactivate the object. Not only will this probably solve your positioning problem, it will perform better - instantiating objects has a performance cost that’s higher than simply enabling them.
2 Likes
Agreed. If it’s a child of the cloud, it will move with the cloud, so you can just turn it on or off as needed. As far as determining when it should go off. You’ll probably need some sort of timer, depending on how you have it coded though will determine what you’ll be best with.
1 Like
Thanks! I just needed a little logic help here. I got a co-routine turning it off and on now with SetActive(true) or SetActive(False).
Instantiating it under as a child on another game object is what was throwing me off.