void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Player" & pickedUp == false) { pickedUp = true; player.itemCount++; player.totalValue += value; bool copyNotFound = true; for (int i = 0; i < player.itemsCollected.Count; i++) { if (player.itemsCollected[i].name == this.name) { copyNotFound = false; player.itemsCollected[i].number++; break; } } if (copyNotFound) { collected item = new collected(); item.name = this.name; item.number = 1; player.itemsCollected.Add(item); } Destroy(GetComponent <BoxCollider2D>()); //Destroy(this.gameObject); } }
// Start is called before the first frame update void Start() { tempObj = GameObject.Find("obstacle"); scriptInstance = tempObj.GetComponent <collected>(); scriptInstance.collectedEvent += open; }