How can I check value stored in a list when pressing button with the same name?

I’ve assigned how much a person would like to do x activity and have it in a list. Using buttons you can ask the npc what it wants to do from given activities. How would you make it so each button would check the value the npc has for that activity?

This is not from the activities, but its done the same way:
gamingTypes.Add (new Gaming (“Board Games”, Random.Range(-5, 5)));

How can I make so if the button that says “Running”, checks the script for the value the character has in running?

EIT: I have some activities like the ones below. As a start, I’m making it so it generates how much a npc likes those activities, and you can ask the npc if it wants to do X activity.
I’m doing it using buttons, with all the options in the screen, and I wanted to try to make it so, if the player clicks on Running, it would look for “Running”, on the list, and get the value. How should I go about this? Sorry if this is too basic, had been a while since I programmed the last time:

	activity.Add (new Activities ("Fishing", Random.Range(-5, 5)));
	activity.Add (new Activities ("Running", Random.Range(-5, 5)));
	activity.Add (new Activities ("Hunting", Random.Range(-5, 5)));

Good day.

Ypu should check the event trigger system. It allows you to execute a method with parameters, like the button name.

Bye

@tormentoarmagedoom Raises a good idea but didn’t really supply an implementation. Also, I think a Dictionary would simplify this greatly.

A very simple version but this is the code you would put on the NPC:

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

public class Activity : MonoBehaviour {

    Dictionary<string, int> activities =
        new Dictionary<string, int>();

	void Start ()
    {
        activities.Add("Fishing", Random.Range(-5, 5));
        activities.Add("Running", Random.Range(-5, 5));
        activities.Add("Hunting", Random.Range(-5, 5));
    }

    public void GetActivity(string activity)
    {
        print("My " + activity + " is " + activities[activity]);        
    }
}

Of course you would probably want to change the class name to something else like ActivityPool and have a method that helped add activities to the NPC rather than just pop them in at start… among other things.


Here is how to set up a Button for use with this.