public void SpawnBeamToPreviousOrb(Orb previousOrb) { Vector2 beamSpawnPosition; // Spawn beam halfway between orbs beamSpawnPosition = Vector2.Lerp(previousOrb.transform.position, transform.position, 0.5f); previousBeam = Instantiate(orbBeamPrefab, beamSpawnPosition, Quaternion.identity).GetComponent <OrbBeam>(); // Store beam in most recent orb so when the orb is destroyed it can take the beam with it previousOrb.AttachBeam(previousBeam); previousBeam.Initialize(previousOrb.transform.position, transform.position); // Deactivate previous beam previousBeam.gameObject.SetActive(false); }
void SpawnOrb(Vector2 atPosition, bool shouldConnectToPrevious) { Vector2 beamSpawnPosition; // Create orb game object GameObject orbGameObject = Instantiate(orbPrefab, atPosition, Quaternion.identity); Orb orb = orbGameObject.GetComponent <Orb>(); if (shouldConnectToPrevious && mostRecentOrb != null) { // Spawn beam halfway between orbs beamSpawnPosition = Vector2.Lerp(mostRecentOrb.transform.position, atPosition, 0.5f); OrbBeam orbBeam = Instantiate(orbBeamPrefab, beamSpawnPosition, Quaternion.identity).GetComponent <OrbBeam>(); // Store beam in most recent orb so when the orb is destroyed it can take the beam with it mostRecentOrb.AttachBeam(orbBeam); orbBeam.Initialize(mostRecentOrb.transform.position, atPosition); } // Add to list orbs.Add(orb); // Update reference to most recent orb for connecting the next orb mostRecentOrb = orb; }