Unity
ํ์ฅ๋ฉ์๋
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; //ํ์ฅ ๋ฉ์๋ : ๊ธฐ์กด ํด๋์ค ๋ฐ ๋ค๋ฅธ ํด๋์ค์ ์ธ์คํด์ค ๋ฉ์๋๋ฅผ ์ถ๊ฐํ ์ ์์ด, ๊ธฐ๋ฅ์ ํ์ฅํ๋ ๊ธฐ๋ฒ //์กฐ๊ฑด 1 : static ํด๋์ค์ฌ์ผ ํ ๊ฒ(MonoBehaviour๋ ํ์์์ผ๋ฏ๋ก ์์ ์ ๊ฑฐ) public static class Extension { //์ฒซ๋ฒ์งธ ๋งค๊ฐ ๋ณ์ : ํ์ฅํ๋ ค๊ณ ํ๋ ๋์ //this ํ์ฅํ ํด๋์ค ๋๋ ํ์ public static void AddUIEvent(this GameObject go, Action action, Define.UIEvent..
๋ค์ํ๊ฒ ์์ฑํ ์ ์๋ ๋๋ค์
//๋ฌด๋ช ๋ฉ์๋//uIEvent.OnDragHandler += delegate (PointerEventData data){uIEvent.gameObject.transform.position = data.position; }; //๋๋ค์//uIEvent.OnDragHandler += (PointerEventData data) => { uIEvent.gameObject.transform.position = data.position; }; //๋๋ค์//uIEvent.OnDragHandler += (PointerEventData data) => uIEvent.gameObject.transform.position = data.position; //๋๋ค์//uIEvent.OnDragHandler += ((Pointe..
ํฌํค ๋ฌด๋ฃ๋ฒ์ ์ฌ์ฉํ๊ธฐ(4) RPC
์ ์ ๋ค์ด ํจ์๋ฅผ ์คํํ๋ฉด ๋ค๋ฅธ ์ ์ ๋ค๋ ๊ทธ ์ํ๋ฅผ ๋ณผ ์ ์๊ฒ RPCํจ์๋ฅผ ์ฌ์ฉํด์ผํ๋ค. ๊ฐ๋ น, ์ด์ ํ๋ฆฌํฉ์ ์์ฑ์ํค๋ FireBullet()์ ํ๋ ์ด์ด๊ฐ ์คํํ์๊ณ , ์ด ๋์ ์ํ๋ฅผ ๋ค๋ฅธ ํ๋ ์ด์ด๋ค๋ ๋ณด๊ฒ ํ๊ธฐ ์ํด์๋ ์๋์ ๊ฐ์ ์์ ์ด ํ์ํ๋ค. [PunRPC] public void FireBullet() { Instantiate(Resources.Load("bullet"),transform.position,transform.rotation); } if(Input.GetKeyDown(KeyCode.Space)) { //FireBullet(); //ํจ์๋ฅผ ์คํํ๊ณ , ๊ทธ ํจ์๋ฅผ ์คํํ๋ค๋ ๊ฒ์ ๋ค๋ฅธ ํ๋ ์ด์ด์๊ฒ ์ ๋ฌ photonView.RPC("FireBullet",RpcTarget.AllViaSer..
ํฌํค ๋ฌด๋ฃ๋ฒ์ ์ฌ์ฉํ๊ธฐ(3) ์ด๋์ ๋ถ๋๋ฝ๊ฒ ๋ณด์ด๊ธฐ ์ํ Lerp ์ถ๊ฐ
์์ ๊ธ๊ณผ ์ด์ด์ ์์ฑํ๋ ๊ฒ์ ๋๋ค. Transform View ์ปดํฌ๋ํธ๋ฅผ ๋นผ๋ ์ ์๋ํ๋ ์ฝ๋ + ์ฃผ์ using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using Photon.Realtime; //๊ด์ธก ์ปจํธ๋กค๋ฌ //์ํ๋ณํ ๊ด์ธก(๋ฐ์ดํฐ์ ์ฃผ๊ณ ๋ฐ์) public class playerController : MonoBehaviourPunCallbacks, IPunObservable { private Vector3 curPos; private Quaternion curRot; void Start() { } void Update() { if(photonView.IsMine)//๋ด๊ฐ ํด..

ํฌํค ๋ฌด๋ฃ๋ฒ์ ์ฌ์ฉํ๊ธฐ(2) ํ๋ ์ด์ด ๋ค์ ์์ฑ๊ณผ ์ํธ ์ํ ๋๊ธฐํ๋ฅผ ์ํ ๊ธฐ์ด์์
์์ ๊ธ๊ณผ ์ด์ด์ ์์ฑํ๋ ๊ฒ์ ๋๋ค. ์ ๋นํ ์บก์ ํ๋ ๋ง๋ค๊ณ ์ด๋ฆ์ player. rigidbody์ปดํฌ๋ํธ์ PlayerController ํ๋ ๋ฌ์์ฃผ๊ณ (์ถํ ์์ฑ), Photon View ์ปดํฌ๋ํธ์ Photon Transform View ์ปดํฌ๋ํธ๋ ๋ฌ์์ค๋ค. player๊ฐ ์์ง์ผ ์ง๋ฉด์ด ๋ ํ๋ธ ํ๋ ์์ฑํ์ฌ x์ z์ Scale ๊ฐ์ ์์ ๋กญ๊ฒ ์กฐ์ . ์ด ์บก์์ ํ๋ ์ด์ด๋ก ํ๋ํ ๊ฒ์ด๋ค. ์ด ์บก์์ Resources ํด๋๋ฅผ ์๋ก๋ง๋ค์ด์ ๊ทธ ์์ ํ๋ฆฌํฉ์ผ๋ก ๋ง๋ค๊ณ ํ์ด์ด๋ผํค ์ฐฝ ์์ ์๋ player๋ ์ง์ด๋ค. ๋คํธ์ํฌ๋งค๋์ .cs๋ฅผ ์๋์ ๊ฐ์ด ์์ ํด์ค๋ค. public GameObject playerprefab; public Transform spawnspot; void SpawnPlayer() { /..
ํฌํค ๋ฌด๋ฃ๋ฒ์ ์ฌ์ฉํ๊ธฐ(1) ํฌํค ID๋ฐ์์ ์ํฌํธ, ๋ฐฉ์์ฑ
2022๋ ๊ธฐ์ค์ผ๋ก ๊ณผ๊ฑฐ์ ๋ฌธ์๋๋ก ๋ฐ๋ผํ๋ฉด ํฌํค์ด ์๋ ์ ์๋ค. ํด๋น ๊ธ์ 2022๋ 1์ 4์ผ ๊ธฐ์ค์ผ๋ก ํฌํคPUN2๊ฐ ๋์๊ฐ๋ ๊ฒ์ ํ์ธํ๊ณ ์์ฑํ๋ ๊ธ์ด๋ค. ์์์ ๋ฉํฐํ๋ ์ด์ด ๊ฒ์์ ์ ์ ๋ ๋ฌด๋ฃ ํฌํค์ผ๋ก ์์ฉ๊ฐ๋ฅํ๋ค. ์๋ ํฌํค ์ฌ์ดํธ์ ๊ฐ์ ํ์๊ฐ์ ์ ํ ๋ค์์ ์ดํ๋ฆฌ์ผ์ด์ ์์ฑ์ ๋๋ฅด๊ณ ์ ๋นํ ํ๋ก์ ํธ ์ด๋ฆ์ ์จ์ฃผ๋ฉด ID๊ฐ ๋ฌ๋ค. https://www.photonengine.com/ko-KR/Photon ๊ธ๋ก๋ฒ ํฌ๋ก์ค ํ๋ซํผ ์ค์๊ฐ ๊ฒ์ ๊ฐ๋ฐ | Photon Engine Cookie Settings Photon uses cookies to identify you as logged-in user, to improve your experience and for marketing. Review a..
Raycast ์ด์ฉํ์ฌ ํด๋ฆญํ ์ง์ ์ผ๋ก ์ด๋ํ๊ธฐ
VR๊ฐ๋ฐ์ ํ๋ ๋์ค ์ปจํธ๋กค๋ฌ๋ฅผ ์์ง์ด์ง ์๊ณ ๋ ํด๋ฆญํ ์ง์ ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ์ด๋ํด์ฃผ๊ธฐ ์ํ ๋ฐ์์ ์ฐ๊ตฌํ๋ค๊ฐ ์ง ์ฝ๋์์ง๋ง ์ค์ ๋ก ์ฌ์ฉํ์ง๋ ์์๋ค. (1) ํ ์ด๋ธ, ๊ฒ์ํ ๋ฑ์ ์ด๋ ์์น๊ฐ ์ถ๊ฐ๋ ๊ฒฝ์ฐ๋ฅผ ์๊ฐํ์ฌ ๋ฐฐ์ด๋ก ๋ง๋ค์ด์ฃผ๋ฉด ํ์ฅ์ฑ ์ธก๋ฉด์์ ๋์ฑ ์ข์ ๊ฒ ๊ฐ๋ค. (2) ์ ๋ฐ์ดํธ๋ฌธ ์์ if๋ฌธ ์์ ์๋ ๋ก์ง์ ๋ค๋ฅธ ํจ์๋ก ๋ถ๋ฆฌ(๋ ๋ฆฝ)์ํค๋ ๊ฒ์ด ์ฅ๊ธฐ์ ์ธ ์ ์ง๋ณด์์ ๋์ฑ ์ข์ ๊ฒ ๊ฐ๋ค. using System.Collections; using System.Collections.Generic; using UnityEngine; public class tempPlayer : MonoBehaviour { public GameObject head;//ํ๋ ์ด์ด public GameObject tablePos..
์ด๋ฒคํธ
์ด๋ฒคํธ๋ ํ๋ ์ด์ด๊ฐ '์์๋ ์๋ฆผ'์ผ๋ก ์ธ์งํ๋ค. ์ฑ ์์ ํน์ ์ธ ์ ์ฉ ์งํต์ ํ๊ฐ ๋์ฌ์์ ๋ ๋ฒจ์ด ์ธ๋ฆฌ๋ฉด ๋ฐ๊ธฐ๋ ์ ์ ํน์ ์ธ์ด ์ ํํ๋ค๋ ๊ฑธ ์ ์ ์๊ณ ํน์ ์ธ์๊ฒ ๋ฌด์ธ๊ฐ๊ฐ ๋ฐ์ํ์์ ์ง์ํ ์ ์๋ค. ์ด๋ฒคํธ๋ ์ด์ ์ ์ฌํ ์๋ฆฌ๋ก ๋์ํ๋ค. ์ด๋ฒคํธ ๋ฐ์์ ๋ํด ์ค๋น๋ฅผ ๋ ํ๊ณ ์๊ณ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ฉด ๊ทธ์ ๋ฐ๋ผ ์์ ๋ ๋์์ ์ํํ๋ค. ๋ํ ์ด๋ฒคํธ์ ํจ๊ป ๊ด๋ จ ์ ๋ณด๋ฅผ ์ ๋ฌํด ์ด๋ค ์ํฉ์ด ๋ฐ์ํ๋์ง๋ฅผ ์๋ ค์ค ์๋ ์๋ค. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Eventsc : MonoBehaviour { //์ด๋ฒคํธ๋ ์์์ ์ฌ์ฉํด ํต์ ์ ํํ์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์ ๋ ์ ๋ฌํ ์ ๋ณด์ ์ข ๋ฅ..
Delegate
Delegate ์์์ด๋ ์ ์ฒด ์์ ์ค ์ผ๋ถ๋ฅผ ๋๊ตฐ๊ฐ๋ฅผ ๋์ ํด ํจ์จ์ ์ผ๋ก ์ฒ๋ฆฌํ๋ ํํ๋ฅผ ๋งํ๋ค. ๋ ๋ค๋ฅธ ํํ์ ์์์ผ๋ก C# ์ ๋๋ฆญ๊ณผ Action ๋๋ Action๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์ด ์๋ค. ์์์ ์ฌ์ฉํ๋ ์ฃผ์ํ ๋ ๊ฐ์ ํจํด์ ์ค์ ๊ฐ๋ฅ๋ฉ์๋(Configurable method)ํจํด๊ณผ ์์(delegation) ํจํด์ด๋ค. 1. ์ค์ ๊ฐ๋ฅ ๋ฉ์๋ ํจํด ์ผ์ด๋ ํจ์์ ์ผ๋ถ๋ฅผ ๋ค๋ฅธ ๋ฉ์๋๋ก ์ ๋ฌํด ์์ ์ ์๋ฃํ๋๋ฐ ์ฌ์ฉํ๋ ํจํด์ด๋ค. ์ด ํจํด์ ๊ณ ์ ํ ๋ฐฉ์์ ๊ฐ์ง ๊ฐ๋ณ ์ฝ๋๊ฐ ๊ณตํต๋ ์์ ์ ์ํํ ๋ ์ฌ์ฉํ๋ค. ์๋ฅผ ๋ค๋ฉด ๊ฑท๊ธฐ, ๋ฐ๊ธฐ, ํ์ ๋ฑ์ด ์ด์ ํด๋นํ๋ค. ์ด ๋ชจ๋ ์์ ์ ์บ๋ฆญํฐ์ ๊ธฐ๋ณธ ํ์๊ฐ ๋ ์ ์๋ค. using System.Collections; using System.Collections.G..
์ ๋ํฐ Reflection ์ฌ์ฉํ์ฌ ํ ํด๋์ค๋ฅผ ์ปดํฌ๋ํธ๋ก ๊ฐ์ ธ์ค๊ธฐ, ํ ํด๋์ค ์ธ์คํด์ค์ ์ ๊ทผํ๊ธฐ
Reflection์ ์์ฉ ๊ฐ๋ฅํ ๋ถ๋ถ์ด ๊ต์ฅํ ๋ง๋ค. ๋ง์ ๋ก์ง์ ํ์ฉํ ์ ์์ ๊ฒ ๊ฐ์์ ๊ธฐ๋๋๋ค. using System; using System.Reflection; ์ด๋ ๊ฒ ๋์ค์ ์จ์ฃผ์ด์ผ ์ฌ์ฉํ ์ ์๋ค. ํ ํด๋์ค๋ฅผ ์ปดํฌ๋ํธ๋ก ๊ฐ์ ธ์ค๊ธฐ - quantity๋ผ๋ ๋ณ์๋ฅผ ๊ฐ์ง๊ณ ์๋ ์กํธ์ด๋ผ๋ ํด๋์ค๋ฅผ ๋ง๋ค๊ณ ์๋์ ๊ฐ์ด ์์ฑ public class Songpyeon : MonoBehaviour { public int quantity; } using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.Reflection; public class Reflection : Mo..