public void CreateBlob(bool createJoint = true) { Debug.Log($"{gameObject.name}{transform.position}"); if (this.IsFull) { int min = children.Min(child => child.Count); BlobController least = children.Find(child => child.Count == min); least.CreateBlob(); return; } var newObj = new GameObject($"{this.gameObject.name}{children.Count}"); newObj.name = $"{this.gameObject.name}{children.Count}"; var blob = newObj.AddComponent <BlobController>(); var collider = newObj.AddComponent <CircleCollider2D>(); var body = newObj.AddComponent <Rigidbody2D>(); var split = newObj.AddComponent <BlobSplitInteractible>(); var newModel = Instantiate(blobPrefab, blob.transform); split.enabled = false; blob.model = newModel.transform; Debug.Log($"{newObj.name}{newObj.transform.position}"); collider.sharedMaterial = GetComponent <CircleCollider2D>().sharedMaterial; body.sharedMaterial = GetComponent <Rigidbody2D>().sharedMaterial; body.interpolation = GetComponent <Rigidbody2D>().interpolation; body.isKinematic = GetComponent <Rigidbody2D>().isKinematic; body.collisionDetectionMode = GetComponent <Rigidbody2D>().collisionDetectionMode; AddChild(blob, createJoint); newObj.transform.localPosition = new Vector3(Random.Range(-1f, 1f) * size, size, 0f); }
// Start is called before the first frame update void Start() { for (var i = 0; i < blobs; i++) { controller.CreateBlob(false); controller2.CreateBlob(false); } controller.CalcJoints(); controller2.CalcJoints(); }
public void OnCollideWithBlob(BlobController other) { if (picked) { return; } other.CreateBlob(); picked = true; Destroy(gameObject); }