playMaker

Author Topic: pickup and enemy spawning mechanics[Solved]  (Read 1000 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 365
pickup and enemy spawning mechanics[Solved]
« on: September 06, 2022, 05:25:29 PM »
Make an empty game object and put the pickup spawning mechanic in it (instantiate or spawn function with an empty game object variable that you can expose as input so it's easier to use).

Place spawners on your map and put whatever you want to spawn in the input box in the inspector.

Now, further things depend on the mechanics that you are using. Before you start the spawn/instantiate functions, check if the object has been instantiated or not.

First thing is setting up the spawner:

Start>bool test
isPickupInstantiated = true > do nothing
isPickupInstantiated = false > create pickup > set isPickupInstantiated to true

Now, if there is no saving the game during the scene and you reload your scene when you restart the level this should do fine, you will restart the level with all of the pickups respawned and if you didn't pick anything up the score and everything else will be the same if there's no saving the game during the level, only at the start of the level.

If you are restarting the level but you want pickups that have been picked NOT to spawn again then you need the persistence player prefs offer.

Player prefs are quite simple and offer basic variable types, but that's ok since we need only bool.

So, for every spawner you have in the scene, instead of using isPickupInstantiated bool you wil use playerprefs bool which is stored in the registry even when you stop the game, turn off the computer and so on.

We basically have the same thing:

Start> get playerprefs bool > bool test
isPickupInstantiatedPlayerPrefsSpawner1 = true > do nothing
isPickupInstantiatedPlayerPrefsSpawner1 = false > create pickup > set isPickupInstantiatedPlayerPrefsSpawner1 to true

To simplify things a bit so you don't have to remember the keys, name your spawners differently (even only copying them so they have suffix (1), (2) and so on is enough), save their name into the string variable and use that string as a player prefs key.
« Last Edit: September 10, 2022, 04:25:58 PM by colpolstudios »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 365
Re: pickup and enemy spawning mechanics
« Reply #1 on: September 06, 2022, 05:29:19 PM »
I am using the system posted, but the spawned objects must be disabled at the start making it harder to use the system is there a way to use the system but showing the spawned objects?

Now using a different approach but leaving the info as it may be very useful to others!
« Last Edit: September 10, 2022, 04:28:03 PM by colpolstudios »