2d 3

[Unity] 2D Content 제작하기 (4) (OnCollisionEnter2D)

물체 충돌 검사 하기 add Tag를 해 ChickBall 태그를 추가한 후 적용시킨다. Item도 마찬가지로 태그를 추가한다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class cshCannonBall : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnCollisionEnter2D(Collision2D collision) // collision: 충돌된 물체 { if (c..

UNITY 2022.04.25

[Unity] 2D Content 제작하기 (3) (InvokeRepeating, Physics Material)

slope을 생성해 Box Collider 2D를 주고, chickBall 을 Prefab으로 등록한다. order in layer는 2로 두어 가장 앞쪽으로 올 수 있게 한다. 그리고 Rigidbody 2D와 Circle Collider 2D를 준다. cshChickGenerator 스크립트를 작성한다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class cshChickGenerator : MonoBehaviour { public GameObject obj; //ChickBallPrefab 설정 public float interval = 3.0f; //다음에 함수가 호출될 인터벌 void S..

UNITY 2022.04.25

[Unity] 2D Content 제작하기 (2) (Instantiate, Destroy)

CannonBall이라는 객체도 만든 후 rigidbody 2D, Circle Collider 2D 추가한다. CannonBall은 Prefab으로 등록한다. Player의 script를 작성한다. using System.Collections; using System.Collections.Generic; using UnityEngine; public class cshPlayerController : MonoBehaviour { public float speed = 8f;//Player의 이동 속도 public float moveableRange = 5.5f; // 이동 가능한 범위 public float power = 1000f; // CannonBall을 발사하는 힘 // 포탄 발사 변수 추가 publ..

UNITY 2022.04.25