简体   繁体   中英

How to spawn powerups 5 fields in front of the player?

I want to spawn power ups when player reach score from 50 to 100 but I can not find the proper way for me..

So my game is normal runner game with some modifications, my runner goes only on Z axis , Y axis is only when he jumps and X axis he can move to left or to right.. My problem is that i have somepoints where he need to jump so If i spawn prefab on same position as player in front of him it can be spawned where player can not jump..

I have made my terrain with prefabs so one prefab contain one object as parent and with few childs ( actualy object where player moves etc..))

So on some places i have something like this where the cube is player and stars is field where he can move..

在此处输入图片说明

He moves forward constantly and he can jump and he can go to left and right..my problem is how to spawn that prefab of powerup if the stars are not on same distance so If i spawn it and add value to z it will not be on same place..

My thought was to add spawn place on every single star and activate them somehow but then I have problem because i don't know how i can activate only 5 powerups in front of player not actually all of them..

If i instantiate power up and add z axis it will not spawn always on the correct position because the stars don't have the same distance..

Please community help me how i can make my game to spawn power ups on right positions (only on stars and only on 2 stars in front of the player )

Next thought is to make a spawner and when player collect him to everything near him in collider must be activated then spawner destroyed and powerups activated, but i don't know how i can achieve that.. ( seems like best solution? )

They don't have the same distance to what? The player? I'm not sure i get what you're saying, but yes you have to add the z value in this case, it's just which z value you add If you want it to always be the same distance between each power up, make a variable distance and assign it, then add it to the z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM