private void ClickerManager_SpawnItem(Vector3 position, Vector3 normal, GameObject hitObject) { if (shopHasItemSelected) { //Setup required references ShopButton itemButton = shopReference.SelectedItem.GetComponent <ShopButton>(); GameObject item = itemButton.ItemPrefab; CreditOverTimeParent itemScript = item.GetComponent <CreditOverTimeParent>(); string landTag = hitObject.tag; int hitLayer = hitObject.layer; int cost = itemButton.Item.itemPrice; //Check if the object can be placed if (creditManager.HasEnoughCredits(cost)) { if (itemScript.biome.ToString() == landTag || itemScript.biome.ToString() == "All" && hitLayer == LayerMask.NameToLayer("Landmass")) { //Set prefab Values itemScript.creditsPerSecond = itemButton.Item.creditsPerSecond; itemScript.lifeSpan = itemButton.Item.lifeSpan; itemScript.type = itemButton.Item.objectType; itemScript.biome = itemButton.Item.biomeType; //Set location & rotation, then spawn item Quaternion rotation = Quaternion.FromToRotation(transform.up, normal); GameObject go = Instantiate(item, position, rotation); go.transform.parent = GameObject.Find("Objects").transform.Find(itemButton.Item.objectType.ToString()); go.transform.RotateAround(go.transform.position, go.transform.up, Random.Range(0, 360)); go.name = go.name.Replace("(Clone)", "").Trim(); go.GetComponent <CreditOverTimeParent>().Init(); if (itemPlaced != null) { itemPlaced(go); } creditManager.SpendCredits(cost); } else if (itemScript.biome.ToString() != landTag && hitLayer == LayerMask.NameToLayer("Landmass")) { Material[] landMaterials = hitObject.GetComponent <Renderer>().materials; foreach (Material mat in landMaterials) { StartCoroutine(ColourChanger(mat, Color.red)); } } } else { if (!warningPlaying) { StartCoroutine(NotEnoughCreditsWarn(creditText, Color.red)); } } } else { //Debug.Log("No Item Selected in shop"); } }