본문 바로가기

전체 글194

오브젝트 삭제 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Delivery : MonoBehaviour { private void OnCollisionEnter2D(Collision2D other) { Debug.Log("Hello"); } public void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Event") { Destroy(other.gameObject, 0.05f); } } } Destroy()를 쓰면 된다. ... 쉽다! 두 번째 인자인 0.05f는destroy하기 전까지의 딜레이이다. 딜레이 시간 안에 파괴 이펙트 같은 걸 넣으.. 2022. 6. 8.
Tag를 이용해서 Collision(Trigger) 구현 전에 충돌(트리거)을 통해 이벤트를 발생시켜봤지만, 그건 모든 충돌 상황에서 발생하는 로직이었다. 그럼 특정 오브젝트에만 트리거를 심고 싶다면 어떻게 해야할까? 원하는 트리거에 Event 태그를 달아주었다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Collision : MonoBehaviour { private void OnCollisionEnter2D(Collision2D other) { Debug.Log("Hello"); } public void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Event") { Debug.Log(.. 2022. 6. 8.
카메라(시점) 따라가기 캐릭터만 움직이고 카메라가 따라가지 않는다면 결국 조종하는 캐릭터가 화면 밖으로 나가 보이지 않게 될 것이다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class FollowCamera : MonoBehaviour { [SerializeField] GameObject thingToFollow; // this camera should be the same as the car's position void LateUpdate() { transform.position = thingToFollow.transform.position + new Vector3(0, 0, -10); } } 위와 같은 스크립트.. 2022. 6. 8.
[2D] Collision과 Trigger Collision이라는 것은 부딪히는 것이고, 여기에서의 Trigger는 오브젝트끼리 닿았을 때의 트리거를 뜻한다. 따지고 보면 Collision과 Trigger는 결국 비슷한 개념이다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Collision : MonoBehaviour { private void OnCollisionEnter2D(Collision2D other) { Debug.Log("Hello"); } public void OnTriggerEnter2D(Collider2D other) { Debug.Log("Trigger"); } } 유니티에서의 Collision과 Trigg.. 2022. 6. 8.
Input 받아서 조작하기 using System.Collections; using System.Collections.Generic; using UnityEngine; public class Driver : MonoBehaviour { [SerializeField] float steerSpeed = 0.1f; [SerializeField] float moveSpeed = 0.01f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { float steerAmount = Input.GetAxis("Horizontal") * steerSpeed; float moveAmount =.. 2022. 6. 8.
728x90