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

88 lines
2.0 KiB
C#

using SHADE;
using SHADE_Scripting.Audio;
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 RigidBody rb;
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>();
rb = GetComponent<RigidBody>();
collider = GetComponent<Collider>();
if(collider)
collider.GetCollisionShape(0).Density = density;
returnBack = false;
AudioHandler.audioClipHandlers["SFXImpactElastic"] = Audio.CreateAudioClip("event:/Props/impact_elastic");
AudioHandler.audioClipHandlers["SFXImpactHard"] = Audio.CreateAudioClip("event:/Props/impact_hard");
}
protected override void start()
{
GameManager.Instance.totalItemCount += 1;
}
protected override void update()
{
if (returnBack && !dontReturn)
{
if(transform)
transform.LocalPosition = firstPostion;
if (rb)
rb.LinearVelocity = Vector3.Zero;
returnBack = false;
}
}
protected override void onCollisionEnter(CollisionInfo info)
{
if (!caputurePos)
{
firstPostion = transform.LocalPosition;
caputurePos = true;
}
if (playSound)
{
if (currCategory == ItemCategory.LIGHT)
AudioHandler.audioClipHandlers["SFXImpactElastic"].Play();
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
AudioHandler.audioClipHandlers["SFXImpactHard"].Play();
playSound = false;
}
if (info.GameObject.GetScript<Homeowner1>() && !returnBack)
{
returnBack = true;
}
}
protected override void onCollisionExit(CollisionInfo info)
{
playSound = true;
}
}