// PLANET CLICK public void onClickPlanet() { // If clicking on any planet in Scale Mode or Distance Planet, get that planet's info if (currentMode == "ScaleMode" || gameObject.name == "Distance Planet") { // Play planet click sound audioObj.PlaySfx(AudioController.audioClickPlanet); // Disable the clicked planet's button planetButtonScript.ButtonDisable(); // Load planet's info screen StartCoroutine(PlanetInfo()); } // If clicking on a mini planet in Distance Mode, travel to that planet else if (currentMode == "DistanceMode" && gameObject.name != distanceImportScript.planet.name && GameController.planetIsMoving == false) { // Enable the mini planet that corresponds with the current Distance Planet GameObject.Find(distanceImportScript.planet.name).GetComponent <ButtonSwitch>().ButtonEnable(); // Start moving the Distance Planet GameController.planetIsMoving = true; distanceObj.GetComponent <PlanetController>().MiniPlanetClicked(gameObject); } }
// SETUP PLANET public void PlanetSetup(PlanetStats thisPlanet) { // Initialize Variables // Set a reference to the child objects, Name and Image; planetNameObject = gameObject.transform.Find("Name").gameObject; planetImageObject = gameObject.transform.Find("Image").gameObject; // Get the RectTransform of this planet and it's name object. planetRectTransform = GetComponent <RectTransform>(); nameRectTransform = planetNameObject.GetComponent <RectTransform>(); // Get the starting versions of this Mode's co-ords and scale thisModeX = planetRectTransform.anchoredPosition.x; thisModeY = planetRectTransform.anchoredPosition.y; // Get the pixels per unit of the sprite being used ppu = planetImageObject.GetComponent <Image>().sprite.pixelsPerUnit; // Get reference to this planet's button planetButtonScript = gameObject.GetComponent <ButtonSwitch>(); // Initialize audio controller reference audioObj = AudioController.Instance; // Setup the objects in accordance with the current mode currentMode = GameController.currentMode; if (currentMode == "ScaleMode") { // Set the scale of the planet relative to it's diameter diameterInPixels = thisPlanet.diameter * GameController.pixelsPerKm; thisModeScale = diameterInPixels / ppu; planetImageObject.transform.localScale = new Vector2(thisModeScale, thisModeScale); // Keep the name above the scaled planet nameRectTransform = planetNameObject.GetComponent <RectTransform>(); thisModeNameX = nameRectTransform.anchoredPosition.x; thisModeNameY = nameRectTransform.anchoredPosition.y; nameRectTransform.anchoredPosition = new Vector2(thisModeNameX, thisModeNameY + GameController.textScalar * diameterInPixels); } // Setup the distance mode planet to be standard size else if (gameObject.name == "Distance Planet") { // Reset planetIsMoving bool GameController.planetIsMoving = false; // Set this planet's name text position to the Planet Info version var nameX = nameRectTransform.anchoredPosition.x; nameRectTransform.anchoredPosition = new Vector2(nameX, GameController.infoNameY); // Set this planet's position and scale to the default version planetRectTransform.anchoredPosition = new Vector2(GameController.defaultX, GameController.kmPlanetY); planetImageObject.transform.localScale = new Vector2(GameController.defaultScale, GameController.defaultScale); } else if (currentMode == "DistanceMode") { // Get the reference to the Distance Planet and it's import script distanceObj = DistanceController.distanceObj; distanceImportScript = distanceObj.GetComponent <PlanetImport>(); // Disable the button if this mini planet is the same as Distance Planet if (gameObject.name == distanceImportScript.planet.name) { planetButtonScript.ButtonDisable(); } } // Save vector to variable for future use thisModeNameVector = nameRectTransform.anchoredPosition; }