Example #1
0
 private void OnTriggerEnter(Collider collision)
 {
     if (collision.gameObject.tag == "Player")
     {
         PlayerController player = collision.gameObject.GetComponent <PlayerController>();
         player.OnGoop(this);
     }
     else if (collision.gameObject.tag == "PlayerChild")
     {
         ChildCollisionNotifyParent np = collision.gameObject.GetComponent <ChildCollisionNotifyParent>();
         np.OnGoop(this);
     }
 }
Example #2
0
    private Transform EnsureChild(Vector2 center, string name)
    {
        // add our children
        GameObject go;
        Transform  childTransform = transform.Find(name);

        if (childTransform != null)
        {
            go = childTransform.gameObject;
        }
        else
        {
            go = new GameObject(name);
            go.transform.parent = transform;
        }

        // make sure they have a rigid body
        Rigidbody rb = go.GetComponent <Rigidbody>();

        if (rb == null)
        {
            rb = go.AddComponent <Rigidbody>();
        }

        // make sure parent is notified of collisions
        ChildCollisionNotifyParent ccnp = go.GetComponent <ChildCollisionNotifyParent>();

        if (ccnp == null)
        {
            ccnp = go.AddComponent <ChildCollisionNotifyParent>();
        }

        go.transform.localPosition = center;
        go.layer       = 8; // no self collision
        rb.constraints = RigidbodyConstraints.FreezePositionZ |
                         RigidbodyConstraints.FreezeRotationX |
                         RigidbodyConstraints.FreezeRotationY;

        return(go.transform);
    }