계층 프로그래밍

자식물체는 부모 물체와 함께 이동 = 플레이어가 무기를 장착하는 경우
큐브를 sphere에 드래그하여 계층구조 설정 -> 스피어 부모 자식은 큐브 ```c# using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Parent_Child : MonoBehaviour { void Update() { if (Input.GetKey(KeyCode.UpArrow)) //키값 조건문 위쪽 화살표 this.transform.Translate(Vector3.forward * 3.0f * Time.deltaTime); //this(object)에 변환.이동(vector3.직진 z축에(+) * 3.0f * time~ (유니티는 왼손좌표계) if (Input.GetKey(KeyCode.DownArrow)) //키값 조건문 아래쪽 화살표 this.transform.Translate(Vector3.back * 3.0f * Time.deltaTime);

    if(Input.GetKey(KeyCode.P)) //p키 눌렀을 때
    {
        GameObject game_object = GameObject.Find("Cube") as GameObject; //게임오브젠트 변수인 게임_오브젝트 = 게임오브젝트.찾는다(큐브) 게임오브젝트로 반환
        game_object.transform.parent = this.transform; //변수를 부모(Sphere)에다가 집어 넣어준다.  (큐브는 부모에게 적용)
    }
    if (Input.GetKey(KeyCode.N)) //n키를 눌렀을 때
    {
        GameObject game_object = GameObject.Find("Cube") as GameObject;
        game_object.transform.parent = null; //큐브를 부모에게서 분리
    }
} } ```