// DeleteTreeReward.cs using UnityEngine; [CreateAssetMenu(menuName = "Rewards/Delete Specific Tree")] public class DeleteTreeReward : RewardFunction { // You'd need a way to identify the tree. // Option A: Reference the GameObject directly (if it's a persistent object or a prefab) public GameObject treePrefabToDelete; // If deleting an instance based on a prefab // Option B: Find by tag or name public string treeTagToFind = "Tree"; public string treeNameToFind = "MySpecificTree"; // If you have unique names public override void RewardPlayer() { GameObject targetTree = null; if (treePrefabToDelete != null) { // If the reward means destroying any instance of this prefab var sceneObjects = GameObject.FindGameObjectsWithTag(treeTagToFind); // Or just iterate all foreach (var obj in sceneObjects) if (obj.name.Contains(treePrefabToDelete.name)) // Check if it's an instance of the prefab { targetTree = obj; break; } } else if (!string.IsNullOrEmpty(treeNameToFind)) { targetTree = GameObject.Find(treeNameToFind); } else if (!string.IsNullOrEmpty(treeTagToFind)) { targetTree = GameObject.FindWithTag(treeTagToFind); // Finds only one, for multiple you need FindGameObjectsWithTag } if (targetTree != null) { Destroy(targetTree); Debug.Log($"Tree '{targetTree.name}' has been deleted as a reward."); } else { Debug.LogWarning("No tree found to delete with the specified criteria."); } } }