728x90 Unity3D53 Unity & C# ~ 텍스트 사이즈에 맞춰서 width값 설정하기 using UnityEngine; using TMPro; public class Test : MonoBehaviour { public TMP_Text tmpText; private void Awake() { tmpText.GetComponent().sizeDelta = new Vector2(tmpText.preferredWidth, tmpText.preferredHeight); } } - content size filter를 사용하지 못할 때 코드로 사이즈 조정을 해줄 수 있다. 2022. 6. 3. Unity & C# ~ 코루틴으로 회전하기 (Rotate Coroutine) Coroutine rotCoroutine = null; float rotSpeed = 30.0f; public void RotStartFunc() { rotCoroutine = StartCoroutine(CoroutineRotFunc()); } IEnumerator CoroutineRotFunc() { var angles = transform.rotation.eulerAngles; angles.z -= Time.deltaTime * rotSpeed; transform.rotation = Quaternion.Euler(angles); yield return null; rotCoroutine = StartCoroutine(CoroutineRotFunc()); } public void RotStopFunc().. 2022. 5. 31. Unity & C# ~ Button Sprite Swap Scirpt Controller using System.Collections; using UnityEngine; using UnityEngine.UI; public class HUD_ButtonController : MonoBehaviour { [SerializeField] Sprite defaultSprite; [SerializeField] Sprite selectedSprite; [SerializeField] Sprite pressedSprite; [SerializeField] Sprite highlightSprite; Image thisImage; bool isPress = false; bool IsPress { get { return isPress; } set { isPress = value; } } private const f.. 2022. 5. 31. Unity & C# ~ 리모트 버튼에서 스킵 버튼을 눌렀을 때 동작 Coroutine skipCoroutine = null; EventSystem = eventSystem; void Start() { eventSystem = GameObject.Find("EventSystem").GetComponent(); } void SkipFunc() { PlayBT.image.sprite = playSelectedImg; //플레이버튼 선택 이미지 PauseBT.image.sprite = pauseDefaultImg; //일시정지버튼 비활성화 이미지 if (skipCoroutine == null) { skipCoroutine = StartCoroutine("SkipCoroutineFunc"); } else if(skipCoroutine != null) { StopCoroutine(.. 2022. 5. 31. Unity & C# ~ Singleton(싱글톤) //예제1 private static T _instance = null; public static T _Instance { get { if (_instance == null) { _instance = FindObjectOfType(typeof(T)) as T; } return _instance; } } //예제2 private static T _instance = null; public static T _Instance { get { if (_instance == null) { _instance = FindObjectOfType(typeof(T)) as T; if (_instance == null) { GameObject obj = new GameObject(); obj.name = "NAME"; _in.. 2022. 5. 20. Unity 문제 해결 ~ ScrollRect가 잘 안 될 때 scrollrect가 들어있는 gameOjbect에 Image가 컴포넌트로 함께 추가 되어 있을 경우, Image 컴포넌트로 인해 스크롤링이 방해 받을 수 있다. 2022. 4. 27. 이전 1 ··· 3 4 5 6 7 8 9 다음 SMALL