using SHADE; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using System.Xml.Linq; public class Breakable : Script { public float threshHold = 1.0f; public bool ignoreRaccoon = false; private RigidBody rb; private Transform trans; public bool isBreak { get; set; } private List itemPieces = new List(); public bool print = false; protected override void awake() { rb = GetComponent(); if (!rb) Debug.LogError("RIGIDBODY EMPTY"); trans = GetComponent(); if(!trans) Debug.LogError("TRANSFORM EMPTY"); foreach (GameObject pieces in GameObject) { itemPieces.Add(pieces); pieces.SetActive(false); } isBreak = false; } protected override void update() { if (isBreak) Break(); } protected override void onCollisionEnter(CollisionInfo info) { if (ignoreRaccoon && info.GameObject.GetScript()) return; if (print) Debug.Log($"{info.GameObject.Name}"); if (rb.LinearVelocity.GetSqrMagnitude() > threshHold && !info.GameObject.GetScript()) { isBreak = true; if(GameObject.GetScript()) GameManager.Instance.totalItemCount -= 1; } } protected override void onTriggerEnter(CollisionInfo info) { } private void Break() { foreach (GameObject item in itemPieces) { item.SetActive(true); item.GetComponent().GlobalPosition = trans.LocalPosition + item.GetComponent().LocalPosition; if (item.GetScript()) GameManager.Instance.totalItemCount += 1; GameObject gO = item; gO.Parent = GameObject.Null; } isBreak = false; Audio.PlaySFXOnce2D("event:/Props/impact_break"); GameObject.SetActive(false); } }