public void OnCollisionStay(Collision collision) { if (GetComponent<Pickup>() != null && GetComponent<Pickup>().IsPickedUp) return; if (collision.gameObject.GetComponent<StickyGroup>() != null) { group = collision.gameObject.GetComponent<StickyGroup>(); AddToOwnGroup(this); } if (collision.gameObject.GetComponent<StickyObject>() != null) { if (!IsPartOfGroup && !collision.gameObject.GetComponent<StickyObject>().IsPartOfGroup) { // Disabled for gameplay reasons //CreateStickyGroup(); } else if (!IsPartOfGroup) { collision.gameObject.GetComponent<StickyObject>().AddToOwnGroup(this); } else if (!collision.gameObject.GetComponent<StickyObject>().IsPartOfGroup) { AddToOwnGroup(collision.gameObject.GetComponent<StickyObject>()); } else { } } }
void CreateStickyGroup() { Debug.Log("New sticky group from " + gameObject); var go = new GameObject("Sticky Group"); group = go.AddComponent<StickyGroup>(); go.AddComponent<Rigidbody>(); go.transform.position = transform.position; transform.parent = go.transform; Destroy(transform.GetComponent<Rigidbody>()); }