본문 바로가기

유니티(Unity)

오브젝트 정보 UI 에 표시하기

https://ksjportfolio.netlify.app/

 

Unity WebGL Player | L7_Store

 

ksjportfolio.netlify.app

Department store의 포털에 들어가면 컨셉 씬을 볼 수 있다.

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ClothDataSheets : MonoBehaviour
{
    public Sprite clothImage; // cloth image source
    public int clothCost;
    public string demonstration;
 
    public Image imageBox;  // source image import to UI Image object
    public TMP_Text demonstrationBox; //TextMeshProUGUI 는 텍스트를 바꿀수는 있어도 text오브젝트에 직접연결 못한다. public 선언 해주더라도 하이라키창에서 인스펙터창의 스크립트에 UI를 직접 연결 못함.
    public TMP_Text costBox;
    
    void OnEnable()
    {
        imageBox.sprite = clothImage;
        costBox.text = clothCost.ToString() + " $";
        demonstrationBox.text = demonstration;
    }
}
 
cs

옷 오브젝트의 하위 빈 오브젝트 생성 후 위 스크립트를 넣어준다. OnEnable을 사용한 이유는 오브젝트가 활성화 될때마다 실행 될 수 있게 하기 위해서 이다.

'유니티(Unity)' 카테고리의 다른 글

Unity Netcode 절차  (0) 2022.11.19
Unity 동기 비동기 async await  (0) 2022.10.26
커서 잠금 시 스크롤 뷰 마우스 휠 사용 안됨. 해결방법  (0) 2022.10.25
Unity Relay서버  (0) 2022.10.25
namespace  (0) 2022.10.10