PowerUp prefab and Game Manager

Hi All

Im still making my Block Breaker game and unfortunate came to a small problem. When i make an gameobject everything is ok but as soon as i make my prefabs they all lost connection to my Game Manager. That is small problem with block that are already in the scene but make huge problem when block drop PowerUp’s all i have is error:

NullReferenceException: Object reference not set to an instance of an object
PowerUpAddLive.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/PowerUpAddLive.cs:32)

Problem is when paddle pick up powerup and in the script calls Game Manager to add points and lives. Is there a way to go around this problem???

OK I found solution :smiley:
just in start of the powerup script one line of code :

gameManager = GameObject.FindObjectOfType ();

and thats it :smiley:

Hey, What PowerUps are you making? I would love to add them to my game too. Is it hard to do?

for now i have 2 :slight_smile: one for extra live and one for extra points :slight_smile:

Have few “extra” in my mind just have to work on code for them :slight_smile: to see if its work. Exept that standard: extra ball on the screen, meteor shower witch will destroy random block’s

Is it hard? Dont know as long as You know what You want to achieve should be easy + You still learning how to work with Unity and C# :slight_smile:

with that problem i was fighting for few days but i read a lot on internet and unity documentation and as always when i give’up and ask for help … tha daaaa solution came to mind :slight_smile:

Privacy & Terms