Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Archives
Today
Total
관리 메뉴

브래의 슬기로운 코딩 생활

모바일 게임 실무 5주차 정리 (RaycastHit, NavMeshAgent) 본문

2-2/모바일 게임 실무

모바일 게임 실무 5주차 정리 (RaycastHit, NavMeshAgent)

김브래 2023. 10. 6. 21:53

spawnPoint = gameObject.transform.GetChild(0).gameObject //자식 객체를 스폰포인트 변수로 지정

 

IEnumerator Shoot() //코루틴 선언,정의

{

Rigidbody rb = spawnPoint.GetComponent<Rigidbody>(); // 스폰포인트의 Rigidbody를 rb 변수에 저장rb.AddForce(spawnPoint.transforn.forward*30f); // 스폰포인트를 앞으로 30만큼의 힘을 가함yield return new WaitForSeconds(1f); // 1초 기다린후 코루틴 종료}

 

void Update(){StartCoroutine("Shoot"); // Shoot 코루틴 시작}

  

GameObject bullet2 = Instantiate(Resources.Load(“bullet", typeof(GameObject))) as GameObject;  // bullet 객체를 복제해서 bullet2로 만듦

Rigidbody rb = bullet2.GetComponent<Rigidbody>(); 

bullet2.transform.rotation = bullet.transform.rotation; 

bullet2.transform.position = bullet.transform.position;

rb.AddForce(bullet2.transform.forward * 500f);

Destroy(bullet2, 1); // 1초 후 bullet2 파괴