void SetOrbite(GameObject newPlanet) { orbitPoint = newPlanet; planetBehavior = orbitPoint.GetComponent <Planet_Behavior>(); transform.parent = orbitPoint.transform; Circle newOrbit = orbitPoint.GetComponentInChildren <Circle>(); if (newOrbit) { // Set the position on the orbite var normPos = new Vector2(transform.localPosition.x, transform.localPosition.y).normalized; transform.localPosition = new Vector3( normPos.x * newOrbit.xRadius * newOrbit.gameObject.transform.localScale.x, normPos.y * newOrbit.yRadius * newOrbit.gameObject.transform.localScale.y, transform.localPosition.z ); } }
void SetOrbite(GameObject newPlanet) { // Set old orbit color if (orbitPoint) { Circle oldOrbit = orbitPoint.GetComponentInChildren <Circle>(); if (oldOrbit) { oldOrbit.SetColor(oldOrbit.defaultColor); } } // Move to next orbit orbitPoint = newPlanet; planetBehavior = orbitPoint.GetComponent <Planet_Behavior>(); if (planetBehavior) { planetBehavior.isWaiting = false; } transform.parent = orbitPoint.transform; Circle newOrbit = orbitPoint.GetComponentInChildren <Circle>(); if (newOrbit) { // Update orbits color newOrbit.SetColor(currentOrbitColor); // Set the position on the orbite var normPos = new Vector2(transform.localPosition.x, transform.localPosition.y).normalized; transform.localPosition = new Vector3( normPos.x * newOrbit.xRadius * newOrbit.gameObject.transform.localScale.x, normPos.y * newOrbit.yRadius * newOrbit.gameObject.transform.localScale.y, transform.localPosition.z ); } // Sound transferSource.pitch = UnityEngine.Random.Range(0.95f, 1.05f); transferSource.Play(); IsReadyTochange = false; }