IEnumerator PushPlateRoutine() { if (!filled || !triggerCol.enabled) { yield break; } var p = plate; plate = null; triggerCol.enabled = false; p.enabled = true; var rigid = p.GetComponent <Rigidbody>(); rigid.isKinematic = false; rigid.AddForce(transform.forward * 200); rigid.AddTorque(Random.onUnitSphere, ForceMode.Impulse); p.gameObject.tag = "Teller"; p.onBroke.RemoveAllListeners(); var col = p.GetComponent <Collider>(); col.isTrigger = true; onEmptied?.Invoke(); yield return(new WaitForSeconds(0.2f)); col.isTrigger = false; yield return(new WaitForSeconds(1)); triggerCol.enabled = true; }
void OnBreak() { var rigid = plate.GetComponent <Rigidbody>(); rigid.isKinematic = false; plate.onBroke.RemoveAllListeners(); onEmptied?.Invoke(); plate = null; }
void OnTriggerEnter(Collider other) { //Debug.Log("trigggerr"); if (other.tag == "Teller" && !other.attachedRigidbody.isKinematic && !filled) { if (other.TryGetComponent(out plate)) { if (!plate.BaseModel.activeSelf || plate.type != plateType) { plate = null; return; } plate.enabled = false; other.attachedRigidbody.isKinematic = true; plate.ResetModel(); other.tag = "Untagged"; plate.onBroke.AddListener(OnBreak); StartCoroutine(Snap(other)); onFilled?.Invoke(); } } }
private void Awake() { mainBrain = GetComponent <PlateBrain>(); }