#null GameOBject

1 messages · Page 1 of 1 (latest)

native lodge
#

Show your code for the weapon controller.

#

the error is on line 16, so the variable you're using there will be the thing to look at

royal perch
native lodge
#

ah yeah, ownedWeapons is static

#

when you go to the main menu, all objects in the old scene are destroyed

#

ownedWeapons will now be a list of destroyed objects

#

You could put references to prefabs into that list, perhaps

royal perch
#

I'll try that

native lodge
#

Do you want to preserve the list of weapons when you quit and start a new game?

royal perch
#

Nah I want to go back to only the starting weapon, being the pistol

#

This game will basically be like call of duty zombies

#

Once you exit game or die, everything resets

#

Yeah I dont think it will be possible, the issue I am facing is my muzzle flash as I cannot assign it to my scripts since it is a child of each weapon prefabs

native lodge
#

(this is a very common problem)

#

do you have a Weapon component right now?

#

if so, add a field on it for the muzzle flash, and then, for each prefab, assign the muzzle flash component into that field

#

now you can just access it directly from the Weapon

royal perch
native lodge
#

Perhaps you can use ScriptableObjects for this. Each one would store a reference to a weapon prefab and a cost

#

or, really

#
[System.Serializable]
public struct ShopItem {
  public Weapon prefab;
  public float cost;
}
#

give your shop a list of that ShopItem struct and throw prefabs in there

royal perch
#

Yeah my brain hurts

#

Like I thought I could just check if it was null, something simple, yeah maybe this is too complicated for my second ever game lol

royal perch
#

Thank you for trying to help, I am just going to remove the buying stations in my game, I think I am just going overboard for my second ever game. And when I gain more knowledge I could maybe come back to this

native lodge
#

It would be simpler to just have a few bools on the player that say if you have a weapon unlocked or not