KDT Unity 5주차 팀 프로젝트
2024-01-15 TIL
저번주에 만든 스크립트를 상속받아 해당 오브젝트를 클릭했을 때 화면 밖으로 나가는지 확인하는 스크립트 작성 이벤트 처리용으로 분리하여 수정에 용이함을 더함
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using UnityEngine;
using UnityEngine.InputSystem;
public class InteractController : Interact
{
private enum SelectMotion
{
Back,
Front,
PlayStop
}
[SerializeField] private float ChangeMaxCheckDistance;
[SerializeField] private LayerMask ChangelayerMask;
private SelectMotion currentMotion = SelectMotion.Back;
private InputAction leftClickAction;
private void Awake()
{
maxCheckDistance = ChangeMaxCheckDistance;
layerMask = ChangelayerMask;
leftClickAction = new InputAction(binding: "<Mouse>/rightButton");
leftClickAction.performed += OnLeftClickPerformed;
leftClickAction.performed += OnLeftClickPlayStop;
leftClickAction.canceled += OnLeftClickCanceled;
}
protected override void Update()
{
base.Update();
//if (curInteractObjectCheck)
//{
// MovementObject(currentMotion);
//}
}
private void MovementObject(SelectMotion currentMotion)
{
if(curInteractObject != null)
{
if (currentMotion == SelectMotion.Back)
{
}
else if (currentMotion == SelectMotion.Front)
{
//curInteractObject.GetComponent<Test>().Front();
}
}
}
private void OnEnable()
{
leftClickAction.Enable();
}
private void OnDisable()
{
leftClickAction.Disable();
}
private void OnLeftClickPerformed(InputAction.CallbackContext context)
{
if(currentMotion != SelectMotion.PlayStop)
{
curInteractObjectCheck = true;
}
else
{
curInteractObjectCheck = false;
}
}
private void OnLeftClickCanceled(InputAction.CallbackContext context)
{
curInteractObjectCheck = false;
if (currentMotion == SelectMotion.PlayStop && curInteractObject != null)
{
//curInteractObject.GetComponent<Test>().PlayStop();
}
else if (currentMotion == SelectMotion.Back && curInteractObject != null)
{
curInteractObject.GetComponent<ReplayRecorder>().isClick = false;
}
else if (currentMotion == SelectMotion.Front && curInteractObject != null)
{
}
}
private void OnLeftClickPlayStop(InputAction.CallbackContext context)
{
if (currentMotion == SelectMotion.PlayStop && curInteractObject != null)
{
//curInteractObject.GetComponent<Test>().PlayStop();
}
else if (currentMotion == SelectMotion.Back && curInteractObject != null)
{
curInteractObject.GetComponent<ReplayRecorder>().isClick = true;
}
else if (currentMotion == SelectMotion.Front && curInteractObject != null)
{
}
}
public void OnScrollPerformed(InputAction.CallbackContext context)
{
Vector2 scrollDelta = context.ReadValue<Vector2>();
Debug.Log(scrollDelta);
if (context.phase == InputActionPhase.Started)
{
if (scrollDelta.y > 0)
{
// 마우스 휠이 위로 움직였을 때 다음 열거형 값으로 이동
int nextMotion = ((int)currentMotion + 1) % 3;
currentMotion = (SelectMotion)nextMotion;
//Debug.Log($"Mouse wheel scrolled up. Current motion: {currentMotion}");
}
else if (scrollDelta.y < 0)
{
// 마우스 휠이 아래로 움직였을 때 이전 열거형 값으로 이동
int nextMotion = ((int)currentMotion - 1 + 3) % 3;
currentMotion = (SelectMotion)nextMotion;
//Debug.Log($"Mouse wheel scrolled down. Current motion: {currentMotion}");
}
}
}
}
This post is licensed under CC BY 4.0 by the author.
