Unity(121)
-
[Unity Project] <ShootOut2D> 2D 슈팅 게임 만들기(2) 배경 설정
배경화면 에셋을 하나 복사하여 두개를 나란히 V키 스냅을 이용해 위와 같이 배치한다. Pixels Per Unit 값을 조정해 화면보다 조금 크게 조절한다. 배경화면 스크롤횡스크롤 게임이기 때문에 배경화면을 왼쪽으로 계속 움직여야 한다. 스크립트를 하나 만들어 조절한다. 왼쪽의 배경이 일정 값 이상 넘어가면 오른쪽으로 다시 옮겨서 무한 반복되게 만들어야 한다. public class BGScript : MonoBehaviour{ public float bgspeed = 2; SpriteRenderer bgspr; void Start() { bgspr = GetComponent(); } void Update() { transform.po..
2023.08.24 -
[C#] Static 변수 / Static 함수 / Static 변수의 자기참조
public class Test : MonoBehaviour{ public static int number; void Start() { Test.number = 20; print(Test.number); MyStaticFunc(10); } public static void MyStaticFunc(int a) { print(Test.number + a); }}static 변수 number를 생성하였고, static 함수 myStaticFunc()를 생성하였다.(**static 함수 안에서는 멤버변수를 사용할 수 없고 함수 입력 인자, 함수 내부 변수 또는 static 변수가 들어가야 한다. 외부 변수는 class의 메모..
2023.08.24 -
[Unity Project] <ShootOut2D> 2D 슈팅 게임 만들기(1) 플레이어 설정
간단한 횡 스크롤 2D 슈팅 게임을 만들어 보고자 한다. Asset Store에서 무료 에셋을 다운받을 수 있다. Warped Space Shooter | 2D 캐릭터 | Unity Asset StoreElevate your workflow with the Warped Space Shooter asset from Ansimuz. Find this & more 캐릭터 on the Unity Asset Store.assetstore.unity.com 반복될 필요 없는 스프라이트 이미지이기 때문에[Wrap Mode] - [Clamp]로 설정하고, 선형 보간이 필요 없기 때문에 [Filter Mode] - [Point]로 설정하고 [Max size]는 스프라이트 크기에 맞게 32로 설정, [Compress..
2023.08.23 -
[Unity] 오브젝트 통과와 충돌, 제거(Collider / Rigid Body / Destroy)
오브젝트 통과하나의 게임 오브젝트가 다른 오브젝트와 충돌하면 OnTriggerEnter를 호출하게 되며 둘 다 Collider가 있어야 한다. 플레이어 오브젝트에 Rigid Body가 있어야 하며 Is Kinematic 체크가 활성화되어있어야 한다. 두 오브젝트 모두 Is Trigger 체크박스를 활성화하면 충돌이 발생하지 않으므로 하나에만 체크해야 한다.(**Is Kinematic 체크 활성화는 물리 계산을 하지 않는다는 뜻이다. Kinematic 뜻 자체가 운동학이라는 뜻이라 조금 헷갈린다.) public class MoveScript : MonoBehaviour{ public float speed = 2; private void OnTriggerEnter(Collider other) ..
2023.08.17 -
[Unity] GameObject.Find
GameObject.Findpublic class Test : MonoBehaviour{ GameObject other; void Start() { other = GameObject.Find("Obj2"); other.GetComponent().material.color = Color.red; }}Hierarchy에서 "Obj2"라는 이름의 오브젝트를 찾은 후 색을 바꿀 수 있다. public class Test : MonoBehaviour{ public GameObject other; void Start() { other.GetComponent().material.color = Color.red; }}public Game..
2023.08.16 -
[Unity] 오브젝트의 위치와 이동 (transform.position / transform.Translate / normalized)
오브젝트의 위치 읽어오기public class Test : MonoBehaviour{ void Start() { Vector3 pos; pos = transform.position; print(pos); }}해당 오브젝트의 현재 위치를 읽어오려면 위의 코드를 사용하면 되며, x, y, z 특정 위치를 알고자 한다면 pos = transform.position.x의 형식으로 지정해 주면 된다. 오브젝트 위치 입력하기transform은 프로퍼티 get, set을 쓰기 때문에 transform.position.x = 10; 은 오류가 발생한다. Vector3 값을 transform.position에 대입하면 된다. 아래와 같은 예시로 살펴볼 수 있다...
2023.08.14