I got a simple question to ask. Just Check below code and the question is in the end at the result of code. I hope you guys can help me..
file inventory.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class inventory : MonoBehaviour {
public List<item> tmp = new List<item> ();
public item itema;
itemDatabase database;
// Use this for initialization
void Start () {
int slotAmount = 0;
database = GameObject.FindGameObjectWithTag ("itemDatabase").GetComponent<itemDatabase> ();
//Generate the Slot and Slot Name;
for(int i = 1; i <= 24; i++) {
tmp.Add (new item());
}
itema = database.items [0];
tmp [0] = itema;
tmp [0].itemStock = 1;
Debug.Log (tmp[0].itemID + " - " + tmp[0].itemStock);
itema = database.items [0];
tmp [1] = itema;
tmp [1].itemStock = 2;
Debug.Log (tmp[1].itemID + " - " + tmp[1].itemStock);
itema = database.items [0];
tmp [2] = itema;
tmp [2].itemStock = 3;
Debug.Log (tmp[2].itemID + " - " + tmp[2].itemStock);
Debug.Log (tmp[0].itemID + " - " + tmp[0].itemStock);
Debug.Log (tmp[1].itemID + " - " + tmp[1].itemStock);
}
}
and the result was :
tmp Array [0] : 1 Stock 1
tmp Array [1] : 1 Stock 2
tmp Array [2] : 1 Stock 3
tmp Array [0] : 1 Stock 3 // this array recently stock was 1 now replace with 3 Why it is replace i have use an array ?
tmp Array [1] : 1 Stock 3 // this array recently stock was 2 now replace with 3 Why it is replace i have use an array ?
The Question is on tmp Array[0] and tmp Array[1] it was replace by tmp Array[2].
THanks Dennis