사실 간단한 기능이지만, 기본이므로 나중에 자주 쓰이니 소스를 기록해 둠
1. 부모 클래스
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace RoomEscape
{
public class SceneObject : MonoBehaviour // 자식 객체들은 이 부모 클래스를 이전 받음
{
public RectTransform _infoTextTrans; // 유니티에서 표시해줄 텍스트 객체를 드래그앤 드랍해주기
public string _infoText; // 각각의 텍스트들은 자식 객체에 유니티에서 적어놔줘서 저장해두기
void Start()
{
}
void Update()
{
}
private void OnMouseEnter()
{
_infoTextTrans.gameObject.SetActive(true);
Text text = _infoTextTrans.GetComponent<Text>();
text.text = _infoText;
}
private void OnMouseExit()
{
_infoTextTrans.gameObject.SetActive(false);
}
}
}
2. 자식 클래스
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RoomEscape
{
public class BookShelves : SceneObject // 각각의 오브젝트에 실제적으로 붙여주는 컴포넌트 소스
{
}
}
'유니티 프로그래밍' 카테고리의 다른 글
유니티에서의 C# 싱글톤 사용법 (오브젝트 객체 쉽게 가져오기) (0) | 2022.08.05 |
---|---|
Visual Studio 와 Unity 연계할때 해줘야할 것 (0) | 2022.08.04 |
유니티에서 카메라 각도를 90도씩 제어 하는 법 (0) | 2022.07.27 |
유니티에서 컴포넌트에 붙어있지 않은 스크립트 접근하기 (0) | 2022.07.25 |
유니티에서 형변환 및 사용 (0) | 2022.07.24 |