SHADE_Y3/Assets/Scripts/Gameplay/Item/SC_Item.cs

76 lines
1.6 KiB
C#
Raw Normal View History

using SHADE;
using System;
public class Item : Script
{
public enum ItemCategory
{
LIGHT,
MEDIUM,
HEAVY
}
public int Score = 10;
public ItemCategory currCategory;
public bool returnBack { get; set; }
private Transform transform;
private bool playSound = false;
private bool caputurePos = false;
private Vector3 firstPostion;
private Collider collider;
public float density = 1.0f;
public bool dontReturn = false;
protected override void awake()
{
transform = GetComponent<Transform>();
collider = GetComponent<Collider>();
if(collider)
collider.GetCollisionShape(0).Density = density;
returnBack = false;
}
protected override void start()
{
GameManager.Instance.totalItemCount += 1;
}
protected override void update()
{
if (returnBack && !dontReturn)
{
transform.LocalPosition = firstPostion;
returnBack = false;
}
}
2022-11-21 21:01:44 +08:00
protected override void onCollisionEnter(CollisionInfo info)
{
if (!caputurePos)
{
firstPostion = transform.LocalPosition;
caputurePos = true;
}
if (playSound)
2022-11-21 21:01:44 +08:00
{
if(currCategory == ItemCategory.LIGHT)
2022-11-23 00:44:27 +08:00
Audio.PlaySFXOnce2D("event:/Props/impact_elastic");
2022-11-21 21:01:44 +08:00
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
2022-11-23 00:44:27 +08:00
Audio.PlaySFXOnce2D("event:/Props/impact_hard");
playSound = false;
2022-11-21 21:01:44 +08:00
}
if (info.GameObject.GetScript<Homeowner1>())
{
returnBack = true;
}
2022-11-21 21:01:44 +08:00
}
protected override void onCollisionExit(CollisionInfo info)
{
playSound = true;
}
}