[Solved] Laser Defender Stretch Goal: Destroying Engine flare once spawned

Resolution: Decided to house control of the flares in the Flare objects themselves then used:
renderer.SetActive = false;
renderer.SetActive = true;

For anyone interested, here is the code I ended up using for the LeftFlare object. There is some funkiness with the positioning when the ship reaches the edge of the screen, though.

OK, so here’s the situation: I made a broadside cruiser instead of a triangular ship for my LaserDefender game. I’ve been focusing and expanding on the concept of instantiation. As part of that, I decided to make engine flares appear when I travel from side to side, then disappear when the player releases the relevant arrow key. I got as far as creating them and having them follow the player sprite, but not despawning. Can someone help me with how to use the Destroy() function in this context?
I know it must be something simple that I just can’t see, but I’d appreciate any help I can get. I’ve highlighted the lines I believe will hold the final line of code.

Things I’ve tried:
Destroying the instance from within it’s own script with Input.GetKeyUp()
Destroying the instance with Destroy(leftFlare). The object doesn’t exist in the context.
Extensive searching of the Unity Scripting API seeking answers through searching the web.

Privacy & Terms