Scripting changes for item and added level 1 scene #330

Merged
glencelow merged 10 commits from PlayerController into main 2023-02-02 11:20:20 +08:00
2 changed files with 28 additions and 6 deletions
Showing only changes of commit 19c11447c0 - Show all commits

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()