0

Im trying to pass a static class that holds a double type number, wich is the game currency, and since it has to be available in all scenes (coding in unity) that's the way I saw to access it easily. What I am trying to do here is set the static value in the playerdata script wich is part of my savesystem, so the static value once changed, can be saved between scenes.

this is in the playerdata script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

[System.Serializable]
public class PlayerData
{
   public double money;

  public PlayerData (GameController player)
{
    //This is where I get the error Member 'GameController.money' cannot be accessed with an instance 
    //reference; qualify it with a type name instead
GameController.money = player.money;  

}
}

this is in the GameController script

  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  using UnityEngine.SceneManagement;
  using System;
  public class GameController : MonoBehaviour
  {
  static public double money = 1;
  }
  • 2
    Does this answer your question? [cannot be accessed with an instance reference; qualify it with a type name instead](https://stackoverflow.com/questions/13545346/cannot-be-accessed-with-an-instance-reference-qualify-it-with-a-type-name-inste) – Mark Benningfield Nov 21 '20 at 23:20
  • It would be useful if you post the exact error message you get. – Klaus Gütter Nov 22 '20 at 06:08

1 Answers1

0

Because the value is static you don't need to pass an instance of GameController.

In your example the parameter you're passing is of type GameController just named Player. So when you say player.money that is an instance of GameController trying to reference a static variable of it's type GameController. I suspect you meant to copy over the playerData ( this ) money's value like:

GameController.money = this.money;

or just simplified

GameController.money = money;

you can do that on a setter when money changes.

Molly J
  • 519
  • 5
  • 15