Hello, i was making my inventory system for my game and then i had a problem, i created a new script just to make some test i face this no-sense problem:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Test : MonoBehaviour {
public List<Pig> johnPigList = new List<Pig>();
public List<Pig> peterPigList = new List<Pig>();
void Start () {
peterPigList = johnPigList;
}
void Update () {
if (Input.GetKeyDown(KeyCode.G))
johnPigList[0].quantity++;
}
}
[System.Serializable]
public class Pig
{
public int quantity;
}
ok, i have two generic lists, johnPigList and then peterPigList, at start peter list is equal to john list, thats ok, but then, when i change the quantity variable, the two list changes too, and this on my mind makes no sense because i defined that these two are equal in the start, so then they are two separed lists.