void SpawnPlant() { //spawns a planet Ray ray = Camera.main.ScreenPointToRay(currentTouch); //initialize ray RaycastHit hit; LayerMask layerMask = (1 << 9) | (1 << 10); //only shoot rays at layers 9, 10 (spawn plane and planets) if (Physics.Raycast(ray, out hit, layerMask)) //cast ray { if (hit.transform.gameObject.layer == 9) //if ray hits spawn layer { newPlanet = PlanetPooler.SharedInstance.GetPooledPlanet(); //local reference for planet if (newPlanet != null) //if there is a planet available in pool { newPlanet.SetActive(true); newPlanet.transform.position = hit.point; touchStart = currentTouch; //set touch start point as current touch point arrow.SetActive(true); //display arrow getArrow.Activate(touchStart); //start arrow planetSpawnedNotStarted = true; } } else if (hit.transform.gameObject.layer == 10 && hit.transform.gameObject != null) //if click hits a planet { hit.transform.gameObject.SetActive(false); //destroy that MF } } }