-2

I already made sort of a database, but I'm new to c# so I don't really know how to move one player witch in my code is "Stephen Curry". This would be a trade feature. So how can I move one player to another team?

Heres my code

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

public class NewBehaviourScript : MonoBehaviour
{
    public List<Players> items = new List<Players>();

    void BuildPlayerDatabase()
    {
        Players = new List<Players>()
        {
            new Players(1, "Stephen Curry", "A long range Shooter",
            new Dictionary<string, int>{
                { "Shooting", 98 }
            })
        };
    }
}
Ruzihm
  • 19,749
  • 5
  • 36
  • 48

1 Answers1

1

A way to do this is having a foreign key in your player, that references the team he's in. To test this, you should create two teams (Team A and Team B) and insert them to your db: then assign Curry the key of the newly inserted Team A. Then, the Trade function would be to change Curry's TeamID from Team A to Team B.

waching
  • 147
  • 2
  • 9
  • That being said, this is the most basic, bare bones way to implement it. There are better, and more elegant solutions to this problem, but I think for a simple toy program it's okay. – waching May 06 '21 at 18:28
  • And here is a link for the [code](https://stackoverflow.com/questions/2094239/swap-two-items-in-list) to that. – gbe May 06 '21 at 18:35