This is my first project so please bear with me.
I’ve managed to create a scene which works pretty well - it has floor, player, collisions, physics and some mechanics for decreasing health.
My problem stems from a powerup/powerdown mechanic. I have :
1 prefab (a question mark) which applies a random powerup/powerdown to the player.
When player collides, it applies the affect for 5 secs. I have tested this code and works well (using switch statement for random affect).
I have looked everywhere and cannot find a good example to achieve my last part. This is to:
Spawn the prefab x number of times throughout the level just above the floor (floor is rectangle collider). The X position can be anything, but the Y value needs to be just above the floor.
I need the powerup/down prefab to not overlap anything (including itself) and it needs to be random - i.e. not using a hidden game object for spawn points.
The floor is on it’s own layer which I thought could assist me … psedo code I thought:
if (spawnpoint above floor_layer)
instantiate (powerup, random.range.x, floor_layer.y)
Any advice would be greatly appreciated on this. I looked at raycasting (haven’t really been successful in implementing raycasting though), manual spawn points (not what I prefer).
End result should look like:
- player starts level
- as player runs through, powerups/downs appear throughout the level at ground level.
- my powerup script destroys prefab after applying affect - should remain destroyed.