Guest User

Untitled

a guest
May 8th, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1. public static HealthItem[] itemsInInventory;
  2.  
  3. void Start()
  4. {
  5.     itemsInInventory = new HealthItem[5];
  6. }
  7.  
  8. void OnTriggerEnter2D(Collider2D other)
  9.     {
  10.         if (other.gameObject.tag == "Collectable")
  11.         {
  12.             if (itemsInInventory.Length >= 9)
  13.             {
  14.                 for (int i = 0; i < itemsInInventory.Length; i++)
  15.                 {
  16.                     if (itemsInInventory[i] == null)
  17.                     {
  18.                         HealthItem tempItem = other.GetComponent<HealthItem> ();
  19.                         itemsInInventory[i] = Instantiate(tempItem) as HealthItem;
  20.                         Destroy(other.gameObject);
  21.                         return;
  22.                     }
  23.                 }
  24.             }
  25.         }
Add Comment
Please, Sign In to add comment