Unity/Unity(๊ธฐ์ด)
Unity์์ this์ ์๋ฏธ
๋ณดํต ์คํฌ๋ฆฝํธ๋ ์ค๋ธ์ ํธ์ ๋ฃ๊ณ ์ด๋ค. this๋ ํด๋น ์คํฌ๋ฆฝํธ๋ฅผ ํฌํจํ๊ณ ์๋ ์ค๋ธ์ ํธ ๊ทธ ์์ฒด๋ฅผ ์๋ฏธํ๋ค. ๊ทธ๋ฌ๋ฏ๋ก ์๋ ์์ 1๊ณผ ์์ 2๋ฅผ ์์ฑํ๋ฉด, ๊ฒฐ๊ณผ์ ์ผ๋ก ๋๊ฐ์ ์๊ฐ์ ํจ๊ณผ๊ฐ ๋ํ๋๋ค. using System.Collections; using System.Collections.Generic; using UnityEngine; public class studyScript : MonoBehaviour { void Update() { float x = Input.GetAxis("Horizontal") * 0.05f; float y = Input.GetAxis("Vertical") * 0.05f; this.transform.Translate(new Vector2(x, y)); } } using Sys..
Unity ๋์ ์์ฑ์ Random.Range๋ฅผ ํ์ฉํ์
float rnd = Random.Range(0.0f, 0.5f); 0.0f~0.5f ์ฌ์ด์ ์ซ์๋ฅผ ๋๋ค์ผ๋ก ์์ฑํ์ฌ ๋ณ์ rnd์ ๋ฃ์ด์ฃผ๋ ์ฝ๋์ด๋ค. ์๋ ์์ค์ฝ๋๋ A๋ฅผ ๋๋ฅผ ์, 0.0~0.5 ์ฌ์ด์ ๋์๋ฅผ ์์ฑํ์ฌ ๊ฐ์ ๋ณ์ rnd์ ์ ์ฅํ๊ณ ์ค๋ธ์ ํธ์ transform.position์ Vector3ํ z๊ฐ์ ๋์ ํด ์์น๋ฅผ ๋ฐ๊พธ๋ ์ฝ๋ using System.Collections; using System.Collections.Generic; using UnityEngine; public class studyScript : MonoBehaviour { void Update() { if (Input.GetKeyDown(KeyCode.A)) { float rnd = Random.Range(0.0f, ..
unity ์ํ์ข์ฐ ์ฝ๋ 2๊ฐ์ง Input.GetKey vs Input.GetAxis ๊ทธ๋ฆฌ๊ณ Translate() ํจ์์ ํ์ฉ
//๋ ํธ๋ก๋๋์ ํฝ์ ๊ฒ์์์ ๋ง์ด ๋ณด์ด๋ ๋ฌด๋น์ค๋ฝ๋ค using System.Collections; using System.Collections.Generic; using UnityEngine; public class MOVE : MonoBehaviour { Transform tr; void Update() { tr = GetComponent(); if (Input.GetKeyDown(KeyCode.UpArrow)) { tr.position = new Vector3(tr.position.x, tr.position.y + 1, tr.position.z); } if (Input.GetKeyDown(KeyCode.DownArrow)) { tr.position = new Vector3(tr.position.x, ..
์ ๋ํฐ Quaternion
Quaternion & Quaternion.Euler transform.rotation์ Quaternionํํ์ธ (x, y, z, w)์ ํํ๋ก ํ์๋๋ค. Quaternion.Euler์ Vector3 ๊ฐ์ ๋ฃ์ผ๋ฉด Quaternion ๊ฐ์ผ๋ก ๋ณํ๋๋ค. transfomr.rotation = Quaternion.Euler(new Vector3(30,50,20)); transform.rotation = Quaternion.Euler(30,50,20); // ์์ ๋์ผ ๊ฐ๋ ๋ํ๊ธฐ 1. Vector3 ๊ฐ์ผ๋ก ๋ณํ ํ ๋ํ ๋ค์ Quaternion์ผ๋ก ๋ค์ ๋ณํ. Quaternion originalRot = transform.rotation; Vector3 originalRotVec3 = originalRot...
[์ ๋ํฐ] get set ํ๋กํผํฐ Property(์์ฑ)
c#์์๋ property(์์ฑ)์ด๋ผ๋ ๊ฒ์ด ์๋ค. c++์์๋ ๋ฐ์ดํฐ์ ์๋์ ์ํด getter setter์ ์ฐ๋๋ฐ c#์ get set์ผ๋ก ์ฐ๊ณ ์ด๋ฐ ๋ฐฉ์์ property๋ผ๊ณ ํ๋ค. ํด๋์ค์์ ์ ๋ณด ์๋์ ์ํ์ฌ ํน์ ๋ณ์๋ฅผ private ์ ์ธํ๋ฉด ํด๋์ค ์ธ๋ถ์์๋ access ๋ถ๊ฐ๋ฅํ๋ค. ์ด๋ฐ ๊ฒฝ์ฐ์, ์ธ๋ถ ํด๋์ค์ ๋ฉค๋ฒ๋ณ์์ ๋ํ ์ ๊ทผ์ด ํ์ํ ๊ฒฝ์ฐ(๋ค๋ฅธ ํด๋์ค๊ฐ ํด๋น ๋ณ์๊ฐ์ ๋ฐ๊ฟ์ผ ํ ๊ฒฝ์ฐ) get,set์ ํตํด ์ ๊ทผํ ์ ์๊ฒ ๊ตฌํํด์ผ ํ๋ค. ํ๋กํผํฐ ์ฌ์ฉ๋ฒ private๋ก ์ ์ธํ ๋ณ์๋ฅผ ์ป๊ฑฐ๋ ์ธํ ํ๊ธฐ ์ํด get, set ๋ฉ์๋๋ฅผ ๊ตฌํํด์ผ ํ๋ค. get ์ ๊ทผ์์ ๋ํ ์ฝ๋ ๋ธ๋ก์ ์์ฑ์ ์ฝ์ ๋ ์คํ๋๊ณ , set ์ ๊ทผ์์ ๋ํ ์ฝ๋ ๋ธ๋ก์ ์์ฑ์ ์ ๊ฐ์ ํ ๋นํ ๋ ์คํ๋๋ค. set ..
[์ ๋ํฐ] Debug.Log์ Debug.LogFormat ํ์ฉ. ์ด๋ค ๊ฒ์ ์จ์ผํ ๊น?
Debug.Log : ํน์ง์ " " ์์์ ๋งํ๊ณ ์ถ์ ๋ฐ์ ๋ณ์๋ฅผ ๋ชจ๋ + ๋ก ์ฐ๊ฒฐ void Start() { int a = 10; Debug.Log("A์ ๊ฐ์ : " + a); } ์ถ๋ ฅ| A์ ๊ฐ์ :10 Debug.LogFormat : ํน์ง์ " "๋ด์์ ๋ฏธ๋ฆฌ ๋ณ์์ {index} ํ์ ๊ฐ๋ฅํ๋ฉฐ, ๋ณ์๋ ์ผํ๋ก ์ฐ๊ฒฐ void Start() { for (int i = 0; i
์ ๋ํฐ ์ฝ๋ฃจํด Coroutine
*๊ฐ์ธ ํ์ต์ ์ํ ํฌ์คํ ์ ๋๋ค.* ์ฝ๋ฃจํด(Coroutine) ์ ์ฐจ์ ์ ๋๋ฉ์ด์ ํจ๊ณผ๋ฅผ ์ฃผ๊ณ ์ถ์ ๋ ์ฌ์ฉํ ์ ์๋ค. Update()๋ฌธ์ ํ ํ๋ ์์ ํ๋ฒ์ฉ ํธ์ถ๋๋ ํจ์๋ผ๋ฉด (๊ฒ์ ํ๋ ์ 1์ด์ 60ํ๋ ์์ด ๋์จ๋ค๋ฉด 1์ด์ 60๋ฒ๋๋ ๊ฒฉ์ผ๋ก ํ๋ฒ ๋๋ ๊ฐ๊ฒฉ์ด 60๋ถ์ 1์ด, 80fps๋ผ๋ฉด 80๋ฒ ํธ์ถ) ์ฝ๋ฃจํด(Coroutine)์ ์ ๋ฐ์ดํธ๋ฌธ ๋ด์ ๋ธํํ์ ์ ์ฉ ๋์ ์ ํ๋ ์๊ณผ ์๊ด์์ด ๋ณ๋์ ์๋ธ ๋ฃจํด์์ ์ํ๋ ์์ ์ ์ํ๋ ์๊ฐ๋งํผ ์ํํ ์ ์๋๋ก ์ค์ ๊ฐ๋ฅํ๋ค. ์ด๋ฅผํ ๋ฉด, ์์ํ ํฌ๋ช ํด์ง๋ ํจ๊ณผ๋ฅผ ์ฃผ๊ณ ์ถ์ ๋ update๋ฌธ ์์์ ๋ก์ง์ ๋ง๋ค๋ฉด1์ด๋ ๋์ง ์์ 60ํ๋ ์ ๊ฐ๊น์ด ๋ฐ๋ณตํ๊ธฐ ๋๋ฌธ์ ์์๊ฐ์ ํฌ๋ช ํด์ง๋ ๋ถ์์ฌ๊ฐ ์๊ธฐ๋๋ฐ์ด๋ด๋๋ ์ฝ๋ฃจํด์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ๋ฆฌํ๋ค. - IEnumerator ..
์ ๋ํฐ SetSprite
Declaration public void SetSprite(int index, Sprite sprite); Parameters index The index of the Sprite being modified. sprite The Sprite being assigned. ์์ธ ์์ ์ค์ธ ์คํ๋ผ์ดํธ์ ์ธ๋ฑ์ค์ ๋๋ค. ํ ๋น๋๋ ์คํ๋ผ์ดํธ. ์ง์ ๋ ์ธ๋ฑ์ค์์ ์คํ๋ผ์ดํธ๋ฅผ ์ค์ ํฉ๋๋ค. ์ฝ๋ ์์: for (int i = 0; i