I have problem. I maked script and it doesnt work! Here is error:
A field initializer cannot reference the nonstatic field, method, or property `CollectedItems.inam’
And code for collecting items
using UnityEngine;
using System.Collections;
public class AnotherCollectables : MonoBehaviour {
void OnTriggerEnter2D(Collider2D collider)
{
if(collider.gameObject.tag == "player")
collider.GetComponent<CollectedItems>().inam = this.gameObject;
Destroy (this.gameObject);
}
}
and code for collected items
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CollectedItems : MonoBehaviour {
public GameObject inam;
private GameObject item = inam;
void OnGUI()
{
if(item == inam)
{ string itmTxt = "Zebrano : --- "; }
else { string itmTxt = "Zebrano : " + item.transform.name; }
GUI.Box (new Rect (Screen.width / 2, Screen.height / 2, 150, 150), itmTxt);
}
}