본문 바로가기
728x90

전체 글252

Button Click Timer 설정 1. using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class ButtonTimer : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { [SerializeField] float SetTime; float timeremain; Button UIButton; void Start() { UIButton = GetComponent(); timeremain = SetTime; } public void OnPointerEnter(PointerEventData eventData) { InvokeRepeating("countDown", 0, Time.deltaTime.. 2020. 12. 13.
Button 클릭 시, Sound 효과 설정 1. UI Button 생성 2. Audio Source 생성 3. Audio 적용 파일 ( wav, mp4, mp3 등 )을 프로젝트 창으로 입력해두기. 4. Code 작성 using UnityEngine; public class ButtonSound : MonoBehaviour { public AudioSource ButtonAudio => GetComponent(); public AudioClip OnHover, OnEnter; public void SoundHover() { ButtonAudio.playOnAwake = false; ButtonAudio.PlayOneShot(OnHover); } public void SoundEnter() { ButtonAudio.playOnAwake = fals.. 2020. 12. 13.
Camera 인식 범위 조정 1. Camera의 속성을 확인하고, Debug mode를 통하여 접근 명칭 알아내기 using UnityEngine; public class PlayerMove : MonoBehaviour { public Camera camera; public float camera_time = 0; void Update() { CameraClip(); } void CameraClip() { camera_time = 1 * Time.time; camera_time++; Debug.Log(camera_time); if (camera_time >= 2000 ) { camera.farClipPlane = 100; } if (camera_time < 500) { camera.nearClipPlane = 0.5f; } } } .. 2020. 12. 13.
Skybox 회전하기 1. Asset Store에서 Skybox Material Download 2. Skybox Material을 적용할 Cube Object 1개 생성 3. Code 적용 using UnityEngine; public class Skybox : MonoBehaviour { void Update() { RenderSettings.skybox.SetFloat("_Rotation", Time.deltaTime + 10); } } ** 강사님의 도움으로 작성한 코드이나, 실제 작용이 안되었으므로, 다시 공부하면서 어떻게 작용하는 것인지 확인할 예정 2020. 12. 13.
Light Flicker 만들기 1. Light의 점멸 효과 만들기 using System.Collections.Generic; using UnityEngine; public class LightFlicker : MonoBehaviour { public Light p_light; public float minIntensity = 0f; public float maxIntensity = 1f; // light flicker의 날카로움과 부드러움 조절 / 1: 날카로움 / 50 : 부드러움 [Range(1,50)] public int smoothing = 5; Queue smoothQueue; float lastSum = 0; public void Reset() { smoothQueue.Clear(); lastSum = 0; } void .. 2020. 12. 13.
Object Color Flicker 만들기 준비물 : Flicker 대상 Material, Object 1. Object의 형상을 구현한다. 2. 해당 Object에 적용할 Material을 만든다. 3. Material의 속성을 설정하고, Object에 입힌다. 4. Filcker Code 작성 using System.Collections.Generic; using UnityEngine; public class ColorFlicker : MonoBehaviour { public Renderer Lamp; private Color color; void Start() { // lamp에 color 값 저장 color = Lamp.material.color; } void Update() { colorFlicker(); } void colorFlick.. 2020. 12. 13.
Trigger Enter, Stay, Exit 정리 Trigger : 어떤 물체가 지정된 물체와 부딪혔으나, 부딪혔다는 사실만 인지할 뿐, 어떠한 물리적 변경이 보여지지 않는 경우를 뜻함. 일종의 유령 상태. 충돌 감지의 일종 Trigger의 종류 : Enter, Stay, Exit Trigger 설정된 물체와의 접촉이 시작된 상태에서 1회만 호출. 재호출 하기 위해서는 추가 조건을 걸거나, 트리거와 접촉 분리한 후, 재접촉하면 된다. using UnityEngine; public class TriggerText : Monobehaviour { private void OnTriggerEnter (collison other) { if(other.transform.tag == "1") Debug.Log("Enter 1") } }.. 2020. 12. 13.
App 종료 & 시스템 강제 종료 using UnityEngine; public class Quit : Monobehaviour { public void OnAppExit() { Application.Quit(); // 시스템 강제 종료 #if UNITY_EDITOR System.Diagnostics.Process.GetCurrentProcess().Kill(); #endif } } 2020. 12. 13.
[Unity] RealTime을 Unity TMP text로 표시하기 ◈ 방법 1. 정석 스타일 using System; using UnityEngine; using TMPro; public class TimeCtrl : Monobehaviour { public TMP_Text date_txt; private void FixedUpdate() { date_txt.text = DateTime.Now.ToStrind("yyyy-MM-dd HH:mm:ss tt"); // 연, 월, 일, 시, 분, 초, 오전/오후 } } ◈ 방법 2. 간략화 스타일 - 람다식 사용 () => { } using System; using UnityEngine; using TMPro; public class TimeCtrl : Monobehaviour { public TMP_Text date_txt;.. 2020. 12. 13.