From 19c11447c0d94810df897e8b05419a24c41fdbb1 Mon Sep 17 00:00:00 2001 From: Glence Date: Mon, 16 Jan 2023 21:31:38 +0800 Subject: [PATCH] added base to return item back to original pos --- Assets/Scripts/Gameplay/Item/SC_Item.cs | 27 ++++++++++++++----- .../Gameplay/Player/SC_PickAndThrow.cs | 7 +++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Gameplay/Item/SC_Item.cs b/Assets/Scripts/Gameplay/Item/SC_Item.cs index 86d8c518..ab729d43 100644 --- a/Assets/Scripts/Gameplay/Item/SC_Item.cs +++ b/Assets/Scripts/Gameplay/Item/SC_Item.cs @@ -12,33 +12,48 @@ public class Item : Script public int Score = 10; public ItemCategory currCategory; - private RigidBody rb; - private bool once = false; + public bool returnBack { get; set; } + private Transform transform; + private bool playSound = false; + private bool caputurePos = false; + public Vector3 firstPostion; protected override void awake() { - rb = GetComponent(); + transform = GetComponent(); + returnBack = false; } protected override void update() { + if (returnBack) + { + transform.LocalPosition = firstPostion; + returnBack = false; + } } protected override void onCollisionEnter(CollisionInfo info) { - if (once) + if (!caputurePos) + { + firstPostion = transform.LocalPosition; + caputurePos = true; + } + + if (playSound) { if(currCategory == ItemCategory.LIGHT) Audio.PlaySFXOnce2D("event:/Props/impact_elastic"); else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY) Audio.PlaySFXOnce2D("event:/Props/impact_hard"); - once = false; + playSound = false; } } protected override void onCollisionExit(CollisionInfo info) { - once = true; + playSound = true; } } \ No newline at end of file diff --git a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs index 9c879314..e8820034 100644 --- a/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs +++ b/Assets/Scripts/Gameplay/Player/SC_PickAndThrow.cs @@ -117,6 +117,13 @@ public class PickAndThrow : Script RetrieveItemComponets(); } } + + if (pc.currentState == RaccoonStates.CAUGHT && itemScript) + { + itemScript.returnBack = true; + pc.holdItem = true; + ResetItemObject(); + } } protected override void fixedUpdate()