유니티 심화

SetParent

다모아 2023. 8. 16. 18:14
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    [SerializeField]
    private GameObject gunPrefab;
    [SerializeField]
    private Transform rightWeaponHolder;
    private GameObject weaponGo;
    // Start is called before the first frame update
    void Start()
    {
        this.weaponGo = Instantiate<GameObject>(this.gunPrefab, this.rightWeaponHolder);
        Debug.Log(weaponGo);
        
    }

    private void Update()
    {
        if(Input.GetMouseButtonDown(0))
        {
            weaponGo.transform.SetParent(null);
        }
    }
}