- Home /
Coin Multiplier Power-up using three objects -- Need Help!
Hi there!
So I recently watched Brackeys video on power-ups and I can’t seem to get it to work.
I want it so that when the player collides with the power-up, it doubles the coin amount from 1 to 2 and is on a duration set to 20 seconds. In his video he's only using 2 objects (the player and the power-up), but in mine i'm using 3 (the player, the power-up and the coins). I’ve written the code how Brackeys does it and tweaked it a bit. My problem is that when the player collides with the power-up I get this error in unity.
NullReferenceException: Object reference not set to an instance of an object
PowerUpCM+c__Iterator0.MoveNext () (at Assets/Scripts/PowerUpCM.cs:23)
PowerUpCM is attached to the power-up PickupPoints is attached to the coins (which takes care of adding the coinAmount to my total amount of coins) The coinAmount variable is in the GameManager script which is an object that holds the variables that i'm accessing.
Also I thought i’d add that the coins are a prefab spawning on a platform prefab that spawns randomly, one after the other. Don’t know if that effects anything in the code, but I heard something about nested prefabs. Don't know if that would help at all though. I'm a bit of a noob when it comes to coding still, but hopefully i'll get the hang of it soon. (Paste-bin links below)
https://pastebin.com/V8KEz8ju (PowerUpCM script)
https://pastebin.com/A7qnaYTX (pickupPoints script)
https://pastebin.com/HArKedBF (GameManager script)
If anything else is needed just let me know. Help in anyway is much appreciated, Cheers!
Your answer
![](https://koobas.hobune.stream/wayback/20220612171739im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Coins Multiplier 0 Answers
Select a prefab from shop to Player - 2D Game 0 Answers
Upgrades not applying after first death 2 Answers
In-Game Store Using Collected Coins 3 Answers