Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

I need help with my script

A topic by CodeSkull created Jan 24, 2021 Views: 352 Replies: 10
Viewing posts 1 to 8

Im making a card game and i need the script that generates cards to reload when the player is out of cards. Can someone please tell me how to know if the player is out of cards and how to reload a script.

Submitted

First of all what engine (if any) are you using to make your game? Unity? Unreal?

Also if it happens to be Unity (or something similar) then I would create a game manager script that detects when the player is out of cards then makes a call to your card reloader script to refill the player's inventory. 

(2 edits)

Im using unity and i have no idea how to do that.  I tried making a thing that counts how many cards the player has left, but when the player uses a card, it stays the same

Submitted

reload the scene

Submitted

I think you should not reload the script. make a function that redistributes the cards and call it when the player has 0 cards. To know the number of cards...you first need a variable that records it....maybe store it in player manager script....make a singleton game manager and add this player manager as an object to it.and call the function with an if..else  under update there. I could help more if you share some screenshots of the code and your project structure

Submitted

So from what I understand you have spawn points that spawn random cards from the objects array. It is not clear tho what those below 6 cards represent. So when do you call the function to spawn. And do you call a function when you play a card. Anyways, what I suggest is that make a player manager script...and do all the things like generating cards, playing cards in it...that way you can have a variable of number of cards...and change that variable whenever you play a card or draw cards.

the first image is showing the card spawn points. each spawn point has different card prefabs in the "objects" section, those are the cards that can spawn at that spawn point. the second image is the spawner script

this is the script that destroys the card and changes the health bar when the card is played: 

Submitted

Oh I did not read these comments..so yeah..you definitely need to make a player manager script...make it singleton if you like.

Deleted post