Пример #1
0
 public void BreakApartDimer()
 {
     // Make a monomer and attach it to the hand. This replaces the dimer you were just holding.
     monomerPos = transform.Find("monomer1");
     monomer1   = Instantiate(monomerPrefab, monomerPos.position, monomerPos.rotation, fishtank);
     //monomer1.GetComponent<Rigidbody>().AddForce(-monomer1.transform.forward * Random.RandomRange(0.01f,0.02f), ForceMode.Impulse);
     monomer1.name = "Mo_" + monomer1.GetInstanceID();
     fishtankScript.SetCartoonRendering(monomer1);
     partnerPos = monomer1.transform.Find("partnerPos");
     monomer2   = Instantiate(monomerPrefab, partnerPos.position, partnerPos.rotation, fishtank);
     //monomer2.GetComponent<Rigidbody>().AddForce(-monomer2.transform.forward * Random.RandomRange(0.01f,0.02f), ForceMode.Impulse);
     monomer2.name = "Mo_" + monomer2.GetInstanceID();
     fishtankScript.SetCartoonRendering(monomer2);
     //Debug.Log("Destroying " + gameObject.name);
     Destroy(gameObject);
 }
Пример #2
0
    public void BreakRing(Hand currentHand)
    {
        if (currentHand != null)
        {
            // Drop whatever you're holding
            currentHand.otherHand.DetachObject(currentHand.otherHand.currentAttachedObject);
            currentHand.DetachObject(currentHand.currentAttachedObject);
            Debug.Log(currentHand.otherHand.name + " is hovering over " + gameObject.name + " which is attached to " + currentHand.name);
        }

        // Make a dimer and attach it to the hand. This replaces the ring you were just holding.
        var ring2DimerTransform = transform.Find("tf_ring2dimer");
        var dimer = Instantiate(dimerPrefab, ring2DimerTransform.position, transform.rotation, fishtank);

        dimer.GetComponent <Rigidbody>().AddForce(-dimer.transform.forward * Random.Range(0.01f, 0.02f), ForceMode.Impulse);
        dimer.name = "dimer_" + dimer.GetInstanceID();
        fishTank.SetCartoonRendering(dimer);

        float minDist = 0;

        if (currentHand != null)
        {
            minDist = Vector3.Distance(dimer.transform.position, currentHand.otherHand.hoverSphereTransform.position);
        }
        var match = dimer;

        foreach (Transform child in dimer.transform)
        {
            if (child.name.StartsWith("ring"))
            {
                var childDimer = Instantiate(dimerPrefab, child.transform.position, child.transform.rotation, fishtank);
                childDimer.GetComponent <Rigidbody>().AddForce(-childDimer.transform.forward * Random.Range(0.01f, 0.02f), ForceMode.Impulse);
                childDimer.name = "dimer_" + dimer.GetInstanceID();
                fishTank.SetCartoonRendering(childDimer);

                if (currentHand != null)
                {
                    var dist = Vector3.Distance(child.transform.position, currentHand.otherHand.hoverSphereTransform.position);

                    if (dist < minDist)
                    {
                        minDist = dist;
                        match   = childDimer;
                    }
                }
            }
        }

        // spawn dispersion particle
        if (age > 0.5f)
        {
            DisperseAccretion();
        }
        Destroy(gameObject);

        if (currentHand != null)
        {
            var attachmentFlags = Hand.AttachmentFlags.ParentToHand | Hand.AttachmentFlags.DetachOthers;
            currentHand.otherHand.AttachObject(match, attachmentFlags);
        }
    }