hey, I’m currently working on a game that involves a lot of prefabs for fireballs and enemy spawning. on the enemy prefab I have it so each instantiated enemy has a random amount of money that they drop within an upgradable range, to display the gold and actually add the gold together I need to use a regular script not on a prefab, however it doesn’t let me do that, is their a way around this???
if you need to see the code please let me know, any help is greatly appreciated
Hey @eddiewolfe2002, not entirely sure what you mean… but have you tried creating a MoneyDrop prefab and referencing it from your enemy prefab? When your enemy dies, you can instantiate the MoneyDrop prefab, randomize the money amount, adjust the drop range and position the drop based on the enemy’s death position. If you mean that you have some controller script that you can use to drop the money, you can include a reference to the money drop controller in the enemy class, then link it when you spawn the enemy. Hope that helps, if I didn’t follow what your issue is, please clarify!
that would work to store the total gold count, however the way I want to show your total gold count is through text on the top right that stays. to do that with a prefab I would have to constantly destroy and instantiate the text each time you collect money. not only that but I make it so when you get more gold it counts up to your gold total rather than getting your gold total and because of that each time I get more gold and instantiate another text for the gold it would have to count up to your total gold from zero every time.
I figured it out!!!
moneyOb = GameObject.Find("/moneyText");
moneyOb.GetComponent<moneyText>().money += goldDrop;
moneyOb is a GameObject variable that references the money text object.
then I find the script component of the moneyText and it works