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);
}
}
}
'유니티 심화' 카테고리의 다른 글
Joystick, 앞 뒤 왼 오 애니메이션, 마우스 드래그해서 시야 옮기기 (0) | 2023.08.17 |
---|---|
SpaceShooter2D - 스페이스바 눌러서 총쏘기 (0) | 2023.08.17 |
절대강좌 유니티 - SpaceShooter (0) | 2023.08.16 |
SpaceShooter2D - 움직이기, 가두기, 애니메이션(오른쪽,왼쪽,센터) (0) | 2023.08.16 |
SetParent (0) | 2023.08.16 |