-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitem
89 lines (67 loc) · 2.61 KB
/
item
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Item : MonoBehaviour
{
GameObject player; //개미
GameObject breadEquipPoint; //개미다리
public Rigidbody rb;
Vector3 forceDirection;
public bool isPlayerEnter; //개미와 빵이 접촉했는지 여부를 저장하는 변수
void Awake()
{
player = GameObject.FindGameObjectWithTag("Player"); //플레이어를 찾음
breadEquipPoint = GameObject.FindGameObjectWithTag("EquipPoint"); //장착위치 오브젝트 불러오기
rb = GetComponent<Rigidbody>(); //빵의 리지드바디 가져오기
}
// Start is called before the first frame update
void Start()
{
Debug.Log(player.name); //성공적으로 출력
Debug.Log(breadEquipPoint.name); //성공적으로 출력
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.K))
{
Debug.Log("K버튼이 눌린상태");
transform.SetParent(breadEquipPoint.transform);
transform.localPosition = Vector3.zero;
transform.rotation = new Quaternion(0, -90, 270, 0);
}
if (Input.GetKeyUp(KeyCode.K))
{
transform.parent = null; //상속해제
//transform.parent = transform.parent.parent; //상속해제 두번째 방법
rb.useGravity = true; //빵에 중력설정해서 바닥으로 떨구기
Debug.Log("중력 설정 완료");
rb.mass = 10; //빵의 질량 10으로 설정
}
/*
if (Input.GetKey(KeyCode.K) && isPlayerEnter)
//k키를 눌렀고 && isPlayerEnter가 true일때
{
transform.SetParent(breadEquipPoint.transform); //item의 부모를 breadEquipPoint로 바꾸고 그 위치로 item옮기기
Debug.Log(isPlayerEnter);
//transform.localPosition = Vector3.zero; //로컬포지션을 0으로 초기화
//transform.rotation = new Quaternion(0, 0, 0, 0);
isPlayerEnter = false;
}*/
}
void OnTriggerEnter(Collider other) //isTrigger체크했으므로 onTrigger함수 사용
{ //충돌감지는 되지만 물리적 충돌은 일어나지 않음
if(other.tag == "Player")
{
Debug.Log("접촉함!");
isPlayerEnter = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
isPlayerEnter = false;
}
}
}