배운 것들

만약 열과 행의 갯수가 같다면 카드의 갯수를 for문을 하나만 쓰고도 표현할 수 있다.

float x = i / n;

float y = i % n;

for (int i = 0; i < 16; i++)
        {
            GameObject newCard = Instantiate(card);
            newCard.transform.parent = GameObject.Find("cards").transform;

            float x = (i / 4) * 1.4f;
            float y = (i % 4) * 1.4f;
            newCard.transform.position = new Vector3(x, y, 0);
        }

추가적으로 일반식을 구하여 위치를 맞춰봤다.

public GameObject card;

    public int line = 4;

    void Start()
    {
        for (int i = 0; i < Math.Pow(line, 2); i++)
        {
            GameObject newCard = Instantiate(card);
            newCard.transform.parent = GameObject.Find("Cards").transform;

            
            // (1) 0 (2) 0.5칸 (3) 1칸 ... => (n - 1) * 0.5 칸
            float fitCenterValue = (line - 1) * (1.4f * 0.5f);

            float x = (i / line) * 1.4f - fitCenterValue;
            float y = (i % line) * 1.4f - (fitCenterValue + 0.9f); // 0.9f == 높이 맞춰준 값
            newCard.transform.position = new Vector3(x, y, 0);
        }
    }

배열 랜덤 정렬

아래 배열은 랜덤하게 정렬되는데 UnityEngine.Random.Range(-1f, 1f)에서 item의 각 요소에 랜덤 값을 부여하여 그 부여된 값으로 정렬하기 때문에 랜덤 정렬이 가능한 것이다.

int[] rtans = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7 };
rtans = rtans.OrderBy(item => UnityEngine.Random.Range(-1f, 1f)).ToArray();

'스파르타 Unity 1기' 카테고리의 다른 글

스파르타 Unity 8기 2일차 TIL  (0) 2023.08.08
스파르타 Unity 8기 1일차 TIL  (1) 2023.08.07
사전캠프 4일차  (0) 2023.08.04
사전캠프 2일차  (0) 2023.08.02
사전캠프 1일차  (0) 2023.08.01

배운 것들

고양이 가 너무 빠를 때 VSync를 체크하면 된다.

VSync(Vertical Synchronization = 수직동기화) : 모니터에서 렌더링 할 때 더블 버퍼링을 사용하는데 이 때 모니터의 주파수에 맞게 렌더링 퍼포먼스를 조절하는 것

더블 버퍼링 : 백 버퍼와 프론트 버퍼를 사용해서 다음에 출력될 화면을 백 버퍼에 집어 넣고 화면이 갱신될 때 프론트 버퍼와 백 버퍼를 바꿔치게 해 백 버퍼의 내용을 보여 줌으로써 자연스러운 화면 전환이 일어나게끔 하는 것

피벗을 이용한 체력바 표시

피벗과 UI 이미지 두 개를 겹치는 것을 이용하여 체력바를 표시할 수 있다.

 

2D Rigidbody와 3DRigidbody

3D rigidbody

Kinematic : 물리법칙 받지 X but 충돌처리는 됨    ex) 맵

Dynamic : 물리법칙 O    ex) 플레이어

2D rigidbody

Static : 3D Kinematic과 동치 - 아예 움직이지 않음

Kinematic - AddforceV에는 움직이지는 않는데 간접적인 힘에는 움직임

Dynamic - 다 움직임

 

유니티 OX 퀴즈

2D에서도 Z축이 의미가 있음 - Layer의 역할을 함

우선순위 : Sorting Layer > Order in Layer > Z Position


Destroy는 즉시 파괴가 아니라 1프레임 이후에 파괴된다.

DestroyImmediate()는 에셋을 영구적으로 파괴하고 웬만하면 에디터 모드에서 쓰는 것을 권장한다.

 

참고 : 

https://www.yes24.com/Product/Goods/67305196

 

유니티 그래픽스 최적화 스타트업 - 예스24

게임개발의 최대 난적, 그래픽스 최적화를 다루는 책이 책은 게임개발의 최대 난적이라 할 수 있는 게임개발의 최적화에 대해서 다루는 책이다. 특히 유니티 엔진을 기반으로 게임을 가볍게 만

www.yes24.com

 

https://docs.unity3d.com/Manual/2DSorting.html

 

Unity - Manual: 2D Sorting

2D Sorting Overview Unity sorts Renderers according to a priority order that depends on their types and usages. You can specify the render order of Renderers through their Render Queue. In general, there are two main queues: the Opaque queue and the Transp

docs.unity3d.com

 

https://docs.unity3d.com/ScriptReference/Object.DestroyImmediate.html

 

Unity - Scripting API: Object.DestroyImmediate

This function should only be used when writing editor code since the delayed destruction will never be invoked in edit mode. In game code you should use Object.Destroy instead. Destroy is always delayed (but executed within the same frame). Use this functi

docs.unity3d.com

 

'스파르타 Unity 1기' 카테고리의 다른 글

스파르타 Unity 8기 2일차 TIL  (0) 2023.08.08
스파르타 Unity 8기 1일차 TIL  (1) 2023.08.07
사전캠프 4일차  (0) 2023.08.04
사전캠프 3일차  (0) 2023.08.03
사전캠프 1일차  (0) 2023.08.01

배운 것들

빗방울 피하기 미니게임에서 배운 것들

InvokeRepeating(string methodName, float time, float repeatTime);

반복하여 일정 시간만큼 함수를 실행한다.

.ToString(string format);

ToString()에 문자열으로 형식을 지정할 수 있다.

ex) float limit;     limit.ToString("N2");시 소숫점 2번째자리까지 표시하게 문자열로 바꾼다.

TimeScale = 0인데 르탄이가 멈추지 않는 이유

Time.timeScale과 관련된 움직임들은 멈춘다. ex) fixedUpdate, Time.deltaTime, WaitForSeconds();

ex2) 만약 캐릭터 움직임이 Time.deltaTime이 곱해지면 TimeScale에 영향을 받아 멈추고 아니고 그냥 Vector값을 더해주거나 하면 멈추지 않는다.

아래 코드처럼 Time.deltaTime이 곱해져 있지 않으며 Update안에서 동작하는 르탄이의 이동은 TimeScale에 영향을 받지 않으므로 TimeScale = 0; 이더라도 움직인다.

*추가 : TimeScale이 0이라도 애니메이션을 동작하게 하고 싶다면 Animator - Update Mode - UnscaledTime을 하면 된다.

 

 

참고 : 

https://malbongcode.tistory.com/36

 

Unity - Pause 버튼 구현하기(Time.scaleTime)

예시는 아래와 같음 구현하기 1. Time.timeScale 이용하기 Time.timeScale이란 아래와 같음 슬로우모션이나 더욱빠르게, 혹은 멈추게 할 수 있음 즉, 버튼을 누른 순간 Time.timeScale = 0; 해주면 됨 2. Button으

malbongcode.tistory.com

https://discussions.unity.com/t/animations-ignore-timescale/36591

 

Animations ignore TimeScale

Is it possible to play animations while the TimeScale is 0? I’m talking about bone animations imported from Maya. The basic scenario is that i have a bunch of rigidbodies on screen, i’d like to “pause” the screen on a button press, which plays an a

discussions.unity.com

 

'스파르타 Unity 1기' 카테고리의 다른 글

스파르타 Unity 8기 2일차 TIL  (0) 2023.08.08
스파르타 Unity 8기 1일차 TIL  (1) 2023.08.07
사전캠프 4일차  (0) 2023.08.04
사전캠프 3일차  (0) 2023.08.03
사전캠프 2일차  (0) 2023.08.02

+ Recent posts