So erstellen Sie ein Inventar mit 3 Storage. Zum Beispiel:Wie führe ich eine Inventarisierung auf Unity C# durch?
wenn i drücken Speicher 1-Taste wird es 20 Slots an Inventar zeigen,
wenn i drücken Speicher 2 Taste aus 21 Slots bis 40 Slots an Inventar zeigen werden, und
wenn i push storage 3 button zeigt von 41 Slots bis 60 Slots im Inventar.
so haben Sie alle 60 Steckplätze insgesamt.
unter seinem meinen Code:
inventory.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class inventory : MonoBehaviour {
public List<GameObject> slotsx = new List<GameObject>();
public player Player;
public List<item> itemx = new List<item>();
public GameObject slots;
item itemxs;
public int indexofdragitem;
public Sprite icon;
int sisa;
itemDatabase database;
int totalSlot = 60;
int currentStorage = 1;
int view = 20;
// Use this for initialization
void Start() {
Player = new player();
int slotAmount = 0;
database = GameObject.FindGameObjectWithTag ("itemDatabase").GetComponent<itemDatabase>();
//Generate the Slot and Slot Name;
for(int i = 1; i <= 60; i++) {
GameObject Slot = (GameObject) Instantiate(slots);
Slot.GetComponent<slotScript>().slotNumber = slotAmount;
slotsx.Add(Slot);
Player.items.Add(new item());
addChilParent (this.gameObject,Slot);
//Slot.transform.parent = this.gameObject.transform;
Slot.name = "slot-" + i;
Slot.SetActive(false);
slotAmount++;
}
ShowStorage1();
}
//Add Slot Child To GridSlot Game Object
public void addChilParent(GameObject parentx, GameObject childx) {
childx.transform.SetParent (parentx.gameObject.transform);
}
}
Dank
Update-Code:
public void onClickStorage1() {
HideAllSlot();
ShowStorage1();
}
public void onClickStorage2() {
HideAllSlot();
ShowStorage2();
}
public void onClickStorage3() {
HideAllSlot();
ShowStorage3();
}
public void HideAllSlot() {
GameObject hslot;
for(int i = 1; i <= 60; i++) {
hslot = GameObject.Find("slot-"+i);
hslot.SetActive(false);
}
}
public void ShowStorage1() {
GameObject hslot;
for(int i = 1; i <= 20; i++) {
hslot = GameObject.Find("slot-"+i).SetActive(true);
hslot.SetActive(true);
}
}
public void ShowStorage2() {
GameObject hslot;
for(int i = 21; i <= 40; i++) {
hslot = GameObject.Find("slot-"+i);
hslot.SetActive(true);
}
}
public void ShowStorage3() {
GameObject hslot;
for(int i = 41; i <= 60; i++) {
hslot = GameObject.Find("slot-"+i);
hslot.SetActive(true);
}
}
Fragen Sie nach der Logik, Speicher mit 20 Steckplätzen zu erstellen. Wenn 1 auf den Button 1 klickt, wird 1-20 angezeigt, bei 2 Klick 21-40 und bei 3 wird der 41-60 angezeigt. (Taste -1) * Ansicht +1 => Taste * Ansicht. Angenommen, Button hat den Wert 1,2,3. – Miller
Ja @Miller, Aber ich habe bereits die Antwort unten .. Vielen Dank Miller :) –