유니티 심화

절대강좌 유니티 - Chapter01 [챕터1]

다모아 2023. 8. 16. 18:21

Gun

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Gun : MonoBehaviour
{

    private void Awake()
    {
        Debug.Log("Awake");
    }

    private void OnEnable()
    {
        Debug.Log("OnEnable");
    }

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start");
    }

    private void OnDisable()
    {
        Debug.Log("OnDisable");
    }  
}

 

Player

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);
        }
    }
}