// ScriptA's method which spawns instances of prefab B // GameObject bInstance = Instantiate(prefabB); // ScriptB scriptOnBInstance = bInstance.GetComponent<ScriptB>(); // scriptOnBInstance.referenceToAGameObject = this.gameObject; public void SpawnFuseSegment(int numSegmentsLeft) { instance = this.gameObject; Debug.Log(numSegmentsLeft); if (numSegmentsLeft >= 0) { FuseSegment next = Instantiate( instance, this.gameObject.transform).GetComponent <FuseSegment>(); next.GetComponent <HingeJoint>().connectedBody = GetComponent <Rigidbody>(); next.GetComponent <HingeJoint>().anchor = Vector3.up * 2f; } }
public void LightFuse() { if (fuse_fx) { fuse_fx.GetComponent <ParticleSystem>().Play(); } if (segments.Count > 0) { FuseSegment fs = segments[segments.Count - 1]; fs.Light(fuse_fx); fs.FuseSegmentFinishEvent += delegate { if (segments.Count > 2) { lr.positionCount--; } segments.Remove(fs); LightFuse(); }; } else { FuseFinishEvent?.Invoke(); } }