2016. 8. 4. 23:20
https://blog.naver.com/nagne2011/220779912236
-Unity : UI 손풀기 : 포켓몬스터 느낌의 인벤토리
날도 덥고 시간 놀리기 아쉬워서 우연히 본 포켓몬스터 리소스 가지고 인벤토리를 만들어봤다 특별한 기능...
blog.naver.com
날도 덥고 시간 놀리기 아쉬워서 우연히 본 포켓몬스터 리소스 가지고 인벤토리를 만들어봤다
특별한 기능은 없고, 키보드 화살표 키 를 이용하여 위 아래로 슬롯을 이동시키는 정도
NGUI를 이용해서 sprite를 바꾸는 방법으로 구현했다
슬롯과 슬롯 바로 옆의 위치를 empty오브젝트로 잡아주고
위치와 슬롯 오브젝트를 잡지정해준다
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
if (Input.GetKeyDown(KeyCode.UpArrow))
{
if (currentSlotNum > 0)
{
currentSlotNum--;
}
Debug.Log (currentSlotNum);
if (currentSlotNum == 0) {
selelctSlotImage = "mainImage_1";
} else {
selelctSlotImage = "barImage_1";
}
slot [currentSlotNum].GetComponent<UISprite> ().spriteName = selelctSlotImage;
slot [currentSlotNum + 1].GetComponent<UISprite> ().spriteName = "barImage_0";
this.transform.localPosition = slotPositoon [currentSlotNum].transform.localPosition;
}
|
cs |
그리고 키보드 방향키를 누를때마다
현재 슬롯 넘버를 확인해서 해당 슬롯의 이미지를 바꿔준다
이때 이동한 후에는 기존 위치에 있는 슬롯은 원레 default 이미지로 되돌려준다
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
if (Input.GetKeyDown(KeyCode.DownArrow))
{
if (currentSlotNum < 5)
{
currentSlotNum++;
}
Debug.Log (currentSlotNum);
if (currentSlotNum == 0) {
selelctSlotImage = "mainImage_1";
} else {
selelctSlotImage = "barImage_1";
}
slot [currentSlotNum].GetComponent<UISprite> ().spriteName = selelctSlotImage;
slot [currentSlotNum - 1].GetComponent<UISprite> ().spriteName = "barImage_0";
this.transform.localPosition = slotPositoon [currentSlotNum].transform.localPosition;
}
|
cs |
아래로 가는것도 동일하게 작업해준다
물론 방향은 반대로
이상!
참고로 오늘 낮 최고기온은 36도 였다...헉..
728x90
'유니티' 카테고리의 다른 글
(NGUI) Grid기능으로 볼륨조절 버튼 만들기 (0) | 2022.02.14 |
---|---|
(NGUI) 이미지 해상도 유지 (0) | 2022.02.14 |
유니티 문자열 자르기 (0) | 2022.02.14 |
유니티 파일/폴더 생성, 삭제, 확인 (0) | 2022.02.14 |
유니티 XML 저장/불러오기 (0) | 2022.02.14 |