728x90
728x90
유니티 progress 바 설정하기 플레이어 또는 적의 체력 설정에 활용할 수 있는 이미지 bar를 세팅하는 코드를 작성했다. 마우스 왼쪽 클릭을 하면 bar 왼쪽부터 줄어들도록 만들었다. 씬 뷰에서 UI - Image를 생성해주고 2D SPRITE 이미지를 매핑해주었다. 하이라키 창에서 다음과 같이 세팅값을 설정해주었다. Image Type을 Filled로 변경 후 , Fill Method를 Horizontal로 바꿔주었다. 이는 이미지를 가로 기준으로 맞춰준다고 보면 된다. 옵션들 중 Vertical은 세로 Radial 360은 360도를 기준으로 이미지 변화를 줄 수 있음을 의미한다. Fill origin은 이미지 변경 시작점을 왼쪽부터/오른쪽부터 줄 지를 설정하는 것이다. 마지막으로 Fill Am..
Line Renderer 라인 렌더러 설정하기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Line : MonoBehaviour { public Transform target; public Color c1 = Color.yellow; LineRenderer LR; void Start() { LR = GetComponent(); LR.widthMultiplier = 0.1f; //선 너비 LR.startColor = c1; //선 시작점 색 LR.endColor = c1; //선 끝점 색 } void Update() { if (Input.GetMouseButton(0)) { LR.SetP..
https://docs.unity3d.com/kr/2019.3/ScriptReference/Ray.html UnityEngine.Ray - Unity 스크립팅 API Representation of rays. docs.unity3d.com 유니티 Ray/RaycastHit 설정하기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Ray : MonoBehaviour { public Transform PointObj; Ray ray; RaycastHit hit; // Update is called once per frame void Update() { if(Input.GetMouseButton..
유니티 씬 전환하는 방법 유니티 개발을 하다보면 Scene을 이동해야 하는 경우가 반드시 존재한다. 기본적인 마우스 클릭 만으로 씬을 전환하는 간단한 방법을 구현했다. 가장 먼저 해주어야 할 세팅은 File - Build Setting에서 전환시킬 씬들을 업로드해주는 것이다. 씬들을 드래그앤드롭으로 가져오기만 하고, 따로 build는 해줄 필요 없다. Create Empty를 생성 해 ChgScene 스크립트를 작성하여 연결해주면 된다. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class ChgScene : MonoBehaviour..
슬라이더 UI 한계시간 설정 방법 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class slider1 : MonoBehaviour { private Slider sd; private float TimeRemain = 100f; void Start() { sd = GetComponent(); } void Update() { TimeRemain -= Time.deltaTime; sd.value = TimeRemain; if (TimeRemain
유니티 오브젝트 자동 스폰 방법 오브젝트가 중력이 적용되어 지면에 닿으면 튀게 하는 효과 : 마우스 왼쪽 클릭 - Physical Material - bounciness(1) using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spawner : MonoBehaviour { public GameObject BallPrefab; public float minDelay = 0.1f; public float maxDelay = 1f; public float DestroyDelay = 5f; private IEnumerator coroutine; void Start() { coroutine = Spaw..