728x90 Unity43 Unity & C# ~ 음성 녹음 세팅 using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Start() { AudioSource aud = GetComponent(); aud.clip = Microphone.Start("Built-in Microphone", true, 10, 44100); aud.Play(); } } /* Microphone.Start(deviceName, loop, lengthSec, frequency); deviceName = string형, null값 사용 가능 loop = bool형, lengthSec에 도달하면 레코딩을 계속하거나 AudioClip을 처음부터 레코딩하는지 여부를 표시 lengthSec.. 2022. 6. 8. Unity & C# ~ Anchor에 따른 Position 값 설정 앵커 위치가 바뀐 상태에서 position을 세팅할 때, local 또는 world 좌표로 세팅을 했는데 원하는 위치에 가지 않을 때가 있음. 이건 앵커 좌표와 local, world 좌표가 다른 것 때문에 발생함. 이럴때는 코드로 position값을 설정할 때, local이나 world좌표가 아닌 anchored 좌표로 설정하면 해결됨. anchor 좌표를 설정하기 위해서는 RectTransform 컴포넌트를 찾아야함. //anchoredRect의 x좌표를 anchoredObj의 anchoredPosition x 좌표로 설정하기 var AnchoredX = anchoredObj.GetComponent().anchoredPosition.x; anchoredRect.anchoredPosition = new.. 2022. 6. 7. 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. 이전 1 2 3 4 5 6 7 8 다음 SMALL