From 9110ba527642d62d4429e7b6afb467f5de144783 Mon Sep 17 00:00:00 2001 From: Ino Date: Wed, 24 Sep 2025 05:50:18 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AF=B8=EB=8B=88=EA=B2=8C=EC=9E=84=20?= =?UTF-8?q?=EA=B2=8C=EC=9E=84=EC=A2=85=EB=A3=8C=20=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EB=B9=A0=EB=A5=B4=EA=B2=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ResWork/GameData/LuckyGameObj.prefab | 2 + Assets/Scenes/SampleScene.unity | 25 +++---------- Assets/Scripts/Game/Game_Lucky.cs | 7 ++-- Assets/Scripts/Game/LuckyGameObj.cs | 41 ++++++++++++++++----- 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/Assets/ResWork/GameData/LuckyGameObj.prefab b/Assets/ResWork/GameData/LuckyGameObj.prefab index 543329d..a8d5917 100644 --- a/Assets/ResWork/GameData/LuckyGameObj.prefab +++ b/Assets/ResWork/GameData/LuckyGameObj.prefab @@ -56,6 +56,8 @@ MonoBehaviour: m_image: {fileID: 613301010048255497} go_effect: {fileID: 1752936709684462252} m_Rigidbody2D: {fileID: 1260999574391235090} + velocityThreshold: 0.1 + requiredStopDuration: 0.2 --- !u!222 &2007710277984516474 CanvasRenderer: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index b716cf2..c768125 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -11361,7 +11361,6 @@ GameObject: m_Component: - component: {fileID: 420248621} - component: {fileID: 420248622} - - component: {fileID: 420248623} m_Layer: 5 m_Name: Bot m_TagString: Finish @@ -11383,10 +11382,10 @@ RectTransform: m_Children: [] m_Father: {fileID: 1999037950} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 1, y: 0} + m_AnchorMin: {x: 0.5, y: 0} + m_AnchorMax: {x: 0.5, y: 0} m_AnchoredPosition: {x: 0, y: -25} - m_SizeDelta: {x: 0, y: 50} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!61 &420248622 BoxCollider2D: @@ -11432,20 +11431,8 @@ BoxCollider2D: drawMode: 0 adaptiveTiling: 0 m_AutoTiling: 0 - m_Size: {x: 1080, y: 50} + m_Size: {x: 5000, y: 100} m_EdgeRadius: 0 ---- !u!114 &420248623 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 420248620} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 970655c7570620b4b81080ce46bbd866, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &422178259 GameObject: m_ObjectHideFlags: 0 @@ -25687,7 +25674,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 90} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 0, y: 0.5} - m_AnchoredPosition: {x: -44, y: 0} + m_AnchoredPosition: {x: -200, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!61 &993386007 @@ -42619,7 +42606,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 90} m_AnchorMin: {x: 1, y: 0.5} m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 44, y: 0} + m_AnchoredPosition: {x: 200, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!61 &1626145305 diff --git a/Assets/Scripts/Game/Game_Lucky.cs b/Assets/Scripts/Game/Game_Lucky.cs index 259bc3f..10fba87 100644 --- a/Assets/Scripts/Game/Game_Lucky.cs +++ b/Assets/Scripts/Game/Game_Lucky.cs @@ -136,7 +136,7 @@ public class Game_Lucky : MonoBehaviour { updateTime = false; list_dropobj.ForEach(f => f.GetComponent().StopObj()); - yield return new WaitForSecondsRealtime(3f); + yield return new WaitForSecondsRealtime(0.5f); m_Game_Lucky_Result.Set(m_Amount); StopAllCoroutines(); } @@ -184,15 +184,13 @@ public class Game_Lucky : MonoBehaviour // tf_cup을 터치한 위치의 x 값만 받아서 거기에 위치시킴 Vector3 cupPos = tf_cup.position; - cupPos.x = worldPos.x; + cupPos.x = Mathf.Clamp(worldPos.x, Cup_minX, Cup_maxX); tf_cup.position = cupPos; // 회전 시작 (목표: -150도) targetZ = -150f; isRotating = true; - list_dropobj.ForEach(f => f.GetComponent().Tilt_Cup()); - SoundInfo.Ins.Play_OneShot((eSound)Random.Range(14, 16)); } @@ -212,6 +210,7 @@ public class Game_Lucky : MonoBehaviour if (Mathf.Approximately(newZ, targetZ)) { isRotating = false; + list_dropobj.ForEach(f => f.GetComponent().Tilt_Cup()); } } diff --git a/Assets/Scripts/Game/LuckyGameObj.cs b/Assets/Scripts/Game/LuckyGameObj.cs index f2b1495..370d1bd 100644 --- a/Assets/Scripts/Game/LuckyGameObj.cs +++ b/Assets/Scripts/Game/LuckyGameObj.cs @@ -10,13 +10,39 @@ public class LuckyGameObj : MonoBehaviour public Rigidbody2D m_Rigidbody2D; ProtectedInt32 m_Amount; - bool isCollision; + bool isTiltCup, isCollision; + public float velocityThreshold = 0.1f; // 이 값 이하이면 "거의 없음"으로 판단 + float stoppedTime = 0f; + public float requiredStopDuration = 0.2f; // 0.2초 이상 멈춰야 인정 + + void Update() + { + if (isTiltCup && !isCollision && IsAlmostStopped()) + { + Debug.Log("움직임이 거의 없음"); + Set_Collision(0); + } + } + + bool IsAlmostStopped() + { + bool almostStoppedNow = + m_Rigidbody2D.linearVelocity.sqrMagnitude < velocityThreshold * velocityThreshold && + Mathf.Abs(m_Rigidbody2D.angularVelocity) < velocityThreshold; + + if (almostStoppedNow) + stoppedTime += Time.deltaTime; + else + stoppedTime = 0f; + + return stoppedTime >= requiredStopDuration; + } public void Init(Vector3 pos) { transform.localPosition = pos; - isCollision = false; + isTiltCup = isCollision = false; m_image.enabled = true; go_effect.SetActive(false); m_Amount = 1; m_Amount.Obfuscate(); @@ -30,19 +56,14 @@ public class LuckyGameObj : MonoBehaviour public void Tilt_Cup() { - StartCoroutine(Co_Update()); - } - - IEnumerator Co_Update() - { - yield return new WaitForSeconds(20f); - if (!isCollision) Set_Collision(0); + isTiltCup = true; } private void OnCollisionEnter2D(Collision2D collision) { - if (isCollision || collision == null) return; + if (!isTiltCup || isCollision || collision == null) return; + //Debug.Log(collision.collider.tag + " : " + collision.collider.name); switch (collision.collider.tag) { case "Player":