Вот код скрипта для поднимания:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mirror;
public class Pickup : NetworkBehaviour
{
[SerializeField] private GameObject currentObject;
[Client]
public void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
for(int i = 0; i < other.GetComponent<Inventory>().slots.Length; i++)
{
if (other.GetComponent<Inventory>().isFull[i] == false)
{
other.GetComponent<Inventory>().isFull[i] = true;
Instantiate(currentObject, other.GetComponent<Inventory>().slots[i].transform);
other.GetComponent<Inventory>().Obj[i] = currentObject;
break;
}
}
}
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Mirror;
public class Pickup : NetworkBehaviour
{
[SerializeField] private GameObject currentObject;
[Client]
public void OnTriggerEnter2D(Collider2D other)
{
if (other.CompareTag("Player"))
{
for(int i = 0; i < other.GetComponent<Inventory>().slots.Length; i++)
{
if (other.GetComponent<Inventory>().isFull[i] == false)
{
other.GetComponent<Inventory>().isFull[i] = true;
Instantiate(currentObject, other.GetComponent<Inventory>().slots[i].transform);
other.GetComponent<Inventory>().Obj[i] = currentObject;
break;
}
}
}
}
}
А вот скрипт для инвентаря:
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Inventory : NetworkBehaviour
{
[SerializeField] public GameObject[] slots;
[SerializeField] public bool[] isFull;
[SerializeField] public GameObject[] Obj;
private void Start()
{
slots = GameObject.FindGameObjectsWithTag("Slots");
}
}
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class Inventory : NetworkBehaviour
{
[SerializeField] public GameObject[] slots;
[SerializeField] public bool[] isFull;
[SerializeField] public GameObject[] Obj;
private void Start()
{
slots = GameObject.FindGameObjectsWithTag("Slots");
}
}