Script “Pick up”, which is located on the ship. Inside the ship is a laser that destroys asteroids. According to the plan, the laser should destroy, and the ship, running into the drop-down resources - should pick them up. However, only a laser picks them up, who should not participate in this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Podbor : MonoBehaviour
{
public AInv inventory;
private void OnTriggerEnter2D(Collider2D stolk)
{
if (stolk.gameObject.tag == "Res")
{
//Find existing item in inventory
for (int i = 0; i < inventory.items.Length; i++)
{
if (inventory.items<em>.Name == stolk.GetComponent<AItem>().Name && inventory.items_.stack != inventory.items*.maxStack){*_</em>
inventory.items*.stack++;*
Destroy( stolk.gameObject);
return;
}
}
//Find empty space for new item
for (int i = 0; i < inventory.items.Length; i++)
{
if (inventory.items*.Name == “empty”)*
{
inventory.items*.Name = stolk.GetComponent().Name;*
inventory.items*.stack = stolk.GetComponent().stack;*
inventory.items*.Image = stolk.GetComponent().Image;*
inventory.items*.maxStack = stolk.GetComponent().maxStack;*
inventory.items*.ID = stolk.GetComponent().ID;*
Destroy( stolk.gameObject);
break;
}
}
}
}
}