added base to return item back to original pos

This commit is contained in:
Glence 2023-01-16 21:31:38 +08:00
parent b6724eed77
commit 19c11447c0
2 changed files with 28 additions and 6 deletions

View File

@ -12,33 +12,48 @@ public class Item : Script
public int Score = 10; public int Score = 10;
public ItemCategory currCategory; public ItemCategory currCategory;
private RigidBody rb; public bool returnBack { get; set; }
private bool once = false; private Transform transform;
private bool playSound = false;
private bool caputurePos = false;
public Vector3 firstPostion;
protected override void awake() protected override void awake()
{ {
rb = GetComponent<RigidBody>(); transform = GetComponent<Transform>();
returnBack = false;
} }
protected override void update() protected override void update()
{ {
if (returnBack)
{
transform.LocalPosition = firstPostion;
returnBack = false;
}
} }
protected override void onCollisionEnter(CollisionInfo info) protected override void onCollisionEnter(CollisionInfo info)
{ {
if (once) if (!caputurePos)
{
firstPostion = transform.LocalPosition;
caputurePos = true;
}
if (playSound)
{ {
if(currCategory == ItemCategory.LIGHT) if(currCategory == ItemCategory.LIGHT)
Audio.PlaySFXOnce2D("event:/Props/impact_elastic"); Audio.PlaySFXOnce2D("event:/Props/impact_elastic");
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY) else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
Audio.PlaySFXOnce2D("event:/Props/impact_hard"); Audio.PlaySFXOnce2D("event:/Props/impact_hard");
once = false; playSound = false;
} }
} }
protected override void onCollisionExit(CollisionInfo info) protected override void onCollisionExit(CollisionInfo info)
{ {
once = true; playSound = true;
} }
} }

View File

@ -117,6 +117,13 @@ public class PickAndThrow : Script
RetrieveItemComponets(); RetrieveItemComponets();
} }
} }
if (pc.currentState == RaccoonStates.CAUGHT && itemScript)
{
itemScript.returnBack = true;
pc.holdItem = true;
ResetItemObject();
}
} }
protected override void fixedUpdate() protected override void fixedUpdate()