private IEnumerator Repair(Vector3 newRootPoint)
    {
        var childPos = new List <Vector3>();

        foreach (Transform child in mainBrain.BrokenModel.transform)
        {
            child.GetComponent <Rigidbody>().isKinematic = true;
            childPos.Add(child.position);
        }

        transform.position = newRootPoint;

        for (int i = 0; i < mainBrain.BrokenModel.transform.childCount; i++)
        {
            var child = mainBrain.BrokenModel.transform.GetChild(i);
            child.position = childPos[i];
        }

        var time = 0.0f;

        while (true)
        {
            time += Time.deltaTime;

            var blend = time / RepairTime;
            blend = Mathf.Clamp01(blend);
            foreach (Transform child in mainBrain.BrokenModel.transform)
            {
                child.localPosition = Vector3.Lerp(child.localPosition, Vector3.zero, blend);
                child.localRotation = Quaternion.Slerp(child.localRotation, Quaternion.identity, blend);
            }

            if (blend == 1)
            {
                break;
            }

            yield return(null);
        }

        mainBrain.ResetModel();
    }
Beispiel #2
0
    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();
            }
        }
    }