Get non static element from other class?

I really don’t now by what keyword I should search it.

Basically I got two scripts.

One is Player stats where we define relationships with NPC’s:

using UnityEngine;
using System;

public class PlayerStats : MonoBehaviour {
    [Serializable]

    public class RelationshipsStats
    {
        public int Kate = 0;
        public int Pianist = 0;
        public int Bartender = 0;
    }

    public string PlayerName;
    public int money;
    public RelationshipsStats Relationships = new RelationshipsStats();

}

And second one is Dialog script. When we’re talking with NPC I need to find the right dialog text to use so I need to get current npc’s relationship.

Dialog.cs

relationships = player.GetComponent<PlayerStats>().Relationships;
var currentStats = relationships.getRelationship("Bartender");

Idea was to create additional method in playerStats.RelationshipStats “getStats”, but idk how to return the right integer by given name.

In PHP it would be something like this:

<?php
class Relationships {

    public $bartender = 1;
    public $kate = 2;
    public function getStats ($name)
    {
        return $this->{$name};
    }
}

Can anyone help to convert it to c# or show the right direction?

P.S. I know that I shouldn’t use strings ar “identifiers”. That’s just for test purpose. Gonna give unique ID’s to every NPC’s.

Tried also in dialog script:

var relStats = relationships.GetType().GetProperty("Bartender").GetValue(relationships, null);
public int GetStats(string name)
{
   if(name == "Bartender")
     return Relationships.Bartender;
}

You could also use a switch statement. But, depending on the number of relationships, you probably want a dictionary or something where you can pass in a value and return a value without having to worry about doing an if or switch check for every possible relationship.

Yeah. The main thing I don’t want to use is IF’s and switch’es.
I don’t believe that there isn’t any simple solution in c#.

(Never worked with C#. Main lang is PHP)

If you use a dictionary, you should use the name as the key and the value would be the relationship points. Then you can retrieve the point value from the name by passing in the string as the index. This way you don’t have to create long if/switches.

The other way is to create a class that holds values about the relationship.

So…

public class Relationship
{
public string name;
public int points;
}

Something along those lines. Then you do a list of this and you can do a .Find or a loop to find a matching name. Again, better as you just pass in a string and return the value you want. Of course you can also add additional info. This also depends on what sort of save system you want to implement.