I need some help...

Usually you should post code using code tags rather than screenshots, and include your error messages as text. (Although in this particular case the screenshot coincidentally revealed additional problems…)

That particular error occurs because your “WeaponBuy” variable isn’t specific enough. The particular object you dragged into that field in the inspector may have been something with a variable called “Weapon”, but you didn’t promise to the computer that it would be, you only promised it would be a GameObject. Most GameObjects don’t have a variable called “Weapon”.

You need to change the type of the variable from “GameObject” to something more specific.

But in order to tell you what to put there instead, we first need to discuss some other problems…

You have a file called WeaponBuy.cs but the class you defined inside of it is called NewBehaviourScript. That’s going to cause problems, because if you want to attach your script to an object in Unity, the name of the file and the name of the class have to match. I’m assuming you meant for the class to be called WeaponBuy.

But that will cause further problems, because “WeaponBuy” is already the name of a variable inside of your WeaponType script. You should make the class and the variable have different names so that you can tell them apart. (I don’t recall offhand whether the compiler will force them to have different names in this particular case, but even if it lets you make them the same, it’s a really bad idea.)

So for example, you might change the name of the class inside of WeaponBuy.cs to be “WeaponBuy”, and then you might change the relevant variable inside WeaponType.cs to be declared as something like “public WeaponBuy buy”. In this case, “WeaponBuy” says what kind of variable it is, and “buy” is the name of that specific variable.

1 Like