3 개의 저장소로 인벤토리를 만드는 방법. 예를 들어Unity C#에서 인벤토리 페이징을 만드는 방법은 무엇입니까?
내가 밀면 저장 한 단추는 인벤토리 20 개 슬롯,
내가 밀면 스토리지 (2)은 인벤토리 40 개 슬롯까지 21 개 슬롯에서 표시 할 버튼을
난 경우를 보여줄 것이다 저장 장치 3 푸시 버튼을 누르면 41 개의 슬롯부터 60 개의 슬롯까지 표시됩니다.
그래서 총 60 개의 슬롯이 있습니다.
의 내 코드 아래:
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);
}
}
감사
업데이트 코드 : 내가 저장 한 버튼을 누르면 경우
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);
}
}
20 개의 슬롯이있는 스토리지를 생성하라는 논리를 묻고 있습니까? 1 번 버튼을 1 번 클릭하면 1-20, 2 번을 클릭하면 21-40이 표시되고 3 번을 누르면 41-60이 표시됩니다. (버튼 -1) *보기 +1 => 버튼 *보기. 버튼에 1,2,3이라는 값이 있다고 가정합니다. – Miller
예 @ 밀러,하지만 난 이미 아래 답변을 .. 감사합니다 밀러 :) –