CS0120 Error Code help
Hey, I am very new to code and Im trying to understand inheritance but while testing my code I got this error and I cant figure out how to fix it. Please help me if you know whats wrong. Its specifically on the shoot function line btw. Line 27 and 28
10 Replies
Please format your code properly (including the indentations and removing unnecessary empty lines...) and actually show the error and where it is.
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/
now with readable linebreaks and indentation :p
post a screenshot of the compiler errors, including the details
idk why its so small
and what exactly are lines 18 and 19?
the error indicates you are trying to access
transform
statically, but I can't see any code that actually does thatIt’s at the shoot function
Gun
isn't a Component
or a MonoBehaviour
, so it doesn't know of a transform
member.
it tries to access transform
from the Weapon
class that Gun
is nested in.
but since accessing transform
(which is an instance member) requires a valid instance of Component
to be present (which would be this
in Weapon
), you cannot access that member.
what you probably wanted to do is class Gun : Weapon
, like you did below with class Throw : Weapon
but you should not be nesting classes in this way in the first placeThank you, its working