- Home /
C# Power-up spawn system (selecting and releasing), need help scripting
Hello guys, I'm a beginner unity user and want to script a power-up spawn system for the power-ups I made.
The power-ups are inside a canister, that when the player triggers (by colliding to it) it will instantiate another object which have a power-up effect script - such as deleting enemies that hits it)
Anyway I want a way to spawn the powers in my game; so here my idea on how it will behave.
An ONGUI screen will come out with buttons that represent a power-up - SIMILAR TO THIS
If the player presses the button, it will enable the power-up to spawn in our spawner script
NEED HELP WITH The spawner script always have to check if the game has 4 power-ups, if not, in 5 seconds it will spawn a new RANDOM power-up from a list of power-ups that was unlocked (player enables them by clicking the button from the ONGUI)
The power-ups will shoot random (360) from a point (empty game object)
Then I will add a force to it, so it shoots out
I have the basic Idea on how to do this, but I don't have the experience and knowledge to write the code by myself.
Basically we need to put my power-ups in an array of empty gameobjects, I have at least 13 power-ups that the game can spawn.
Then it has to check if that power-up is activated by a bool i guess,
If it is activated (unlocked by player), then the spawner will random select 4 of those unlocked power-up to spawn in the game... we could probably do this by having a script that checks if the power-up is unlocked and then have it add to another array of only unlocked power-ups,
Then out of those new array of unlocked power-ups, the game will spawn only 4 random power-ups, each time that the game has less than 4, it will wait 5 seconds before spawning a new one.
I think I have the basic Idea just need help with the layout of the script, if you have even a tutorial on how to do it then awesome :)
Please help me guys
Answer by Myth · Oct 05, 2013 at 10:16 PM
use
Array.RemoveAt()
Array.Add()
and
Array.length
to manage the array of power-ups.
you can have the script that detects collision find the spawn object and call a method to remove it from the array.
Too little for me to go on :( I'll have problem getting the script to work as it'll be hard for me to structure this script properly... But I'll go watch a tutorial on how to use arrays...
I'd watch all the beginner series from Unity, especially the scripting ones, good luck :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613115353im_/https://answers.unity.com/themes/thub/images/avi.jpg)