- Home /
[CLOSED] An object reference is required to access non-static member
Hi! I write a script which using function from another script. All is going well, but there're 1 compile fail: An object reference is required to access non-static member 'Inventory.CellPickup'. Code:
Inventory InventScript = Player.GetComponent<Inventory>();
Inventory.CellPickup();
I try to use "InventScript.CellPickup();" instead "Inventory.CellPickup();" but this not fixed the problem. Have you got any ideas to solve my problem?
PS: Sorry for my bad English :/
I was going to say use "InventScript.CellPickup()" but I realize I didn't read carefully. It looks like you tried that.
You would use Inventory.CellPickup() if CellPickup is static, and you should use InventScript.CellPickup() if CellPickup isn't static... do you get the same exact error if you use InventScript.CellPickup()?
Hmmm. The error in $$anonymous$$onoDevelop is the same, but I noticed now that the error in console is other when I use "InventScript.CellPickup()". Fail: Inventory.CellPickup() is inacessible due to its protection level.
Eh... I fixed the problem: I must make the CellPickup method public.
Your answer
Follow this Question
Related Questions
Communication between objects and other scripts, variables and properties 1 Answer
Change variable of ex2D Sprite using the component ExScreenPosition via code .js script 0 Answers
Static variables 1 Answer
Change static variable in JS through Csharp 1 Answer
What's the better practice to use common variable? 0 Answers