private IEnumerator CheckAlignment() { // Continue looping until the game is no longer running. while (m_IsGameRunning) { // If there is a current ring, set it to be unaligned by default. if (m_CurrentRing) m_CurrentRing.ShipAligned = false; // Create a ray forward from the flyer's current position. Ray ray = new Ray (transform.position, Vector3.forward); RaycastHit hit; // Spherecast along the ray. if (Physics.SphereCast (ray, m_Radius, out hit)) { // Try to find a ring on the hit object. Ring ring = hit.transform.GetComponent<Ring> (); // If it is a ring... if (ring) { // ... set it as the current ring and the flyer is aligned with it. m_CurrentRing = ring; m_CurrentRing.ShipAligned = true; } } // Wait until next frame. yield return null; } }
private void HandleRingRemove(Ring ring) { // Now the ring has been removed, unsubscribe from the event. ring.OnRingRemove -= HandleRingRemove; // Remove the ring from it's collection. m_Rings.Remove(ring); // Return the ring to its object pool. m_RingObjectPool.ReturnGameObjectToPool(ring.gameObject); }