게임 매니악스 슈팅 게임 알고리즘에 나오는 방향탄 코드 2-7, 2-8을 Unity에서 테스트해봤습니다. 12345678910111213using UnityEngine; public class InitDirectedBullet{ public static Vector2 GetBulletSpeedVector(float theta) { Vector2 bulletSpeedVector; bulletSpeedVector.x = Mathf.Cos(Mathf.PI / 180 * theta); bulletSpeedVector.y = Mathf.Sin(Mathf.PI / 180 * theta); return bulletSpeedVector; }} Colored by Color Scriptercs 12345678910111..
게임 매니악스 슈팅 게임 알고리즘에 나오는 조준탄 코드 2-1, 2-2를 Unity에서 테스트해봤습니다. 12345678910111213141516171819202122232425262728293031323334353637383940using UnityEngine; public class InitAimingBullet : MonoBehaviour { public Transform enemy; public Transform main; public float bulletSpeed; Vector2 mainPos; Vector2 enemyPos; Vector2 bulletPos; Vector2 bulletSpeedVector; float distance; public Vector2 GetBulletSpeedVe..
12345678910111213141516171819202122232425262728293031using System.Collections;using System.Collections.Generic;using UnityEngine; [ExecuteInEditMode]public sealed class Font : MonoBehaviour{ [SerializeField] private string SortingLayerName = "Default"; [SerializeField] private int SortingOrder = 0; public void OnValidate() { apply(); } public void OnEnable() { apply(); } private void apply() { v..
터치 혹은 마우스 클릭으로 회전 시키고 싶은 타겟의 중심 기준 원을 그리면 타겟이 입력에 따라 회전하게되는 코드입니다. GetAngle 함수를 통해 타겟의 중심인 피벗과 입력(마우스 혹은 터치)의 각도(0~360 범위)를 구하고 구한 각도의 이전 값과 현재 값의 차를 통해 구한 변화량을 타겟의 각도 값에 대입하여 타겟을 회전시킵니다. 1234567891011121314151617181920212223242526272829303132333435363738394041using UnityEngine; public class CircleGesture : MonoBehaviour { public Transform target; float previous; float current; private void Upda..
유니티에서 기본적으로 제공하는 sprite diffuse 셰이더는 sprite 뒷면의 빛 계산을 하지 않습니다. 밑의 셰이더는 앞 뒤 어느 각도에도 같은 빛을 받는 셰이더 입니다. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889Shader "Custom/BackLightDiffuse" { Properties { [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} _Color ("Tint", C..
기본으로 제공되는 PlayerPrefs는 int, float, string 형식만 지원하기 때문에 다른 형식을 지원하는 클래스를 미리 구현하면 편리하게 사용이 가능합니다. 123456789101112131415161718192021222324252627282930313233343536373839public static class PlayerPrefsExtension{ public static void SetBool(string key, bool value) { if (value) PlayerPrefs.SetInt(key, 1); else PlayerPrefs.SetInt(key, 0); } public static bool? GetBool(string key) { int tmp = PlayerPrefs...
화살표(방향 지시 UI)를 목표로 이동시킨 뒤 카메라 범위를 넘어간 거리를 비례식을 통해 변경 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152using System.Collections;using System.Collections.Generic;using UnityEngine; public class Navigation : MonoBehaviour { public float arrowSpeed; public Transform currentLocation; public Transform target; // Update is called once per frame void Update ..
'요청 자체를 캡슐화하는 것입니다. 이를 통해 요청이 서로 다른 사용자를 매개변수로 만들고, 요청을 대기시키거나 로깅하며, 되돌릴 수 있는 연산을 지원합니다.' - GoF의 디자인 패턴 GoF의 디자인 패턴에 나오는 명령 패턴의 설명입니다. 대강 알아는 듣겠지만 정확히 무슨 말인지 모호합니다. 그래서 저는 명령 패턴을 '함수 호출을 객체로 만드는 방법' 이라고 나름대로 정의했습니다. 즉 명령 패턴은 함수 호출 이라는 동작을 객체로 만들기 때문에 이 동작을 저장하거나 함수의 인자로 사용할 수 있게 만듭니다. 명령 패턴의 사용 예로는 함수 호출을 저장하거나 함수의 인자로 사용할 수 있기 때문에 게임에서의 입력키 변경, undo, 등에 사용될 수 있습니다. 명령 패턴의 구현은 Command 인터페이스를 만드는..
1. Firebase 페이지에 접속합니다. https://console.firebase.google.com/ 2. 프로젝트 추가 임의의 프로젝트 이름을 넣고 위치를 대한민국으로 변경한 후 프로젝트 만들기 버튼을 눌러 프로젝트를 생성합니다. 프로젝트 ID는 데이터베이스에 접근할 URL에 사용됩니다. 3. 앱 추가 안드로이드 아이콘을 클릭하여 앱 추가 페이지로 들어갑니다. 이 페이지에서 입력하는 패키지 이름은 유니티 패키지 이름과 동일해야 합니다. google-services.json 파일을 다운로드 합니다. 이 파일은 Unity Assets 폴더에 들어가게 됩니다.https://firebase.google.com/docs/unity/setup?authuser=0#add-the-sdk-android 이곳에서..