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

108 lines
2.5 KiB
C#
Raw Normal View History

using SHADE;
2023-02-03 19:37:18 +08:00
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;
2023-02-21 19:31:50 +08:00
private bool checkSound = false;
public float soundDistance = 10;
protected override void awake()
{
transform = GetComponent<Transform>();
rb = GetComponent<RigidBody>();
collider = GetComponent<Collider>();
if(collider)
collider.GetCollisionShape(0).Density = density;
returnBack = false;
2023-02-03 19:37:18 +08:00
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;
}
2023-02-21 19:31:50 +08:00
if (checkSound)
{
/* //need to wait for collisionEnter Fix
Vector3 itemPos = transform.LocalPosition;
Vector3 len = Homeowner1.aiInstance.GetComponent<Transform>().LocalPosition - itemPos;
Debug.Log($"distance: {len.GetSqrMagnitude()}");
if (len.GetSqrMagnitude() <= soundDistance)
{
//set ai to alert
}
checkSound = false;*/
}
}
2022-11-21 21:01:44 +08:00
protected override void onCollisionEnter(CollisionInfo info)
{
2023-02-21 19:31:50 +08:00
if (!caputurePos)
{
firstPostion = transform.LocalPosition;
caputurePos = true;
}
if (playSound)
2023-02-03 19:37:18 +08:00
{
if (currCategory == ItemCategory.LIGHT)
AudioHandler.audioClipHandlers["SFXImpactElastic"].Play();
2022-11-21 21:01:44 +08:00
else if (currCategory == ItemCategory.MEDIUM || currCategory == ItemCategory.HEAVY)
2023-02-03 19:37:18 +08:00
AudioHandler.audioClipHandlers["SFXImpactHard"].Play();
playSound = false;
2022-11-21 21:01:44 +08:00
}
if (info.GameObject.GetScript<Homeowner1>() && !returnBack)
{
returnBack = true;
}
2022-11-21 21:01:44 +08:00
}
protected override void onCollisionExit(CollisionInfo info)
{
playSound = true;
2023-02-21 19:31:50 +08:00
checkSound = true;
}
}