Originally did through the creation-delete object, but came across a project in the public domain, which does what I want, but in 2D. The project .
In general, as I understood the idea, we change the sprite on the table through a layer through ScriptableObject . 
ps What is OverlaySprite, an empty object? Why is he like a prefab, but gray, although he is active.
Main code:
CropAsset:
using System.Collections; using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(fileName = "New Crop", menuName = "Crop")] public class CropAsset : ScriptableObject { public Sprite seedSprite; public Sprite deadSprite; public Sprite doneSprite; public bool seedIsOnGround = false; } Crop:
using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class Crop { public CropAsset asset; public CropState state; private float growthLevel; private float waterLevel; private bool isDead; public bool Grow(float amount) { if (GetWaterState() == WaterState.Watered) { growthLevel += amount / 20f; } if (growthLevel >= 1f) { state = CropState.Done; return true; } return false; } public WaterState Dry(float amount) { waterLevel -= amount / 8f; return GetWaterState(); } public WaterState GetWaterState () { if (waterLevel > 0f) { return WaterState.Watered; } else if (waterLevel > -1f) { return WaterState.Dry; } else { state = CropState.Dead; return WaterState.Dead; } } public void Water () { waterLevel = 1f; } public Crop (CropAsset a) { asset = a; state = CropState.Seed; growthLevel = 0f; waterLevel = 1f; isDead = false; } public bool HasCrop() { if (asset == null) return false; else return true; } public Sprite GetCropSprite() { if (asset == null) return null; switch (state) { case CropState.Seed: return asset.seedSprite; case CropState.Planted: return asset.seedSprite; case CropState.Dead: return asset.deadSprite; case CropState.Done: return asset.doneSprite; } Debug.LogError("WHAT?!"); return asset.seedSprite; } public bool IsOnGround() { if (state == CropState.Planted && asset.seedIsOnGround) return true; else return false; } public Sprite GetDoneSprite() { return asset.doneSprite; } public string GetName() { if (asset == null) return null; return asset.name; } } public enum CropState { Seed, Planted, Dead, Done } public enum WaterState { Watered, Dry, Dead } Tool:
using System.Collections; using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(fileName = "New Tool", menuName = "Tool")] public class Tool : ScriptableObject { public Sprite sprite; public ToolType toolType; } public enum ToolType { Plow, Watercan } TableTile:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class TableTile : MonoBehaviour { public SpriteRenderer overlay; public Crop crop; public Tool tool; private void Start() { if (crop.HasCrop()) overlay.sprite = crop.GetCropSprite(); else if (tool != null) overlay.sprite = tool.sprite; } public void Interact(Crop c, Tool t, PlayerInteraction player) { player.SetCrop(crop); crop = c; player.SetTool(tool); tool = t; if (tool != null) overlay.sprite = tool.sprite; else if (crop != null) overlay.sprite = crop.GetCropSprite(); else overlay.sprite = null; } } I want to do the same, but for 3D objects. I was recommended to change where Sprite and SpriteRenderer is used to Mesh and MeshRenderer.
My code is:
IngredientAsset:
using System.Collections; using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(fileName = "New Ingredient", menuName = "Ingredient")] public class IngredientAsset : ScriptableObject { public Mesh ingredientMesh; } Ingredient:
using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class Ingredient : MonoBehaviour { public IngredientAsset asset; public Ingredient (IngredientAsset a) { asset = a; } public bool HasIngrediend() { if (asset == null) return false; else return true; } public Mesh GetIngrediendObject() { if (asset == null) return null; return asset.ingredientMesh; } } EquipmentAsset:
using System.Collections; using System.Collections.Generic; using UnityEngine; [CreateAssetMenu(fileName = "New Equipment", menuName = "Equipment")] public class EquipmentAsset : ScriptableObject { public Mesh equipmentMesh; } TableBox:
using System.Collections.Generic; using UnityEngine; public class TableBox : MonoBehaviour { public MeshRenderer overlay; public Ingredient ingredient; public EquipmentAsset equipment; private void Start() { if (ingredient.HasIngrediend()) overlay.mesh = ingredient.GetIngrediendObject(); else if (equipment != null) overlay.mesh = equipment.mesh; } public void Interact(Ingredient c, EquipmentAsset t, PlayerInteraction player) { player.SetIngredient(ingredient); ingredient = c; player.SetEquipment(equipment); equipment = t; if (equipment != null) overlay.sprite = equipment.mesh; else if (ingredient != null) overlay.mesh = ingredient.GetIngrediendObject(); else overlay.mesh = null; } } But since the creation of my ScriptableObjects of the mesh type, in my version Crop swears at overlay.mesh .
The table itself:
Overlay:
Please help me figure out how to convert this function to 3D objects. Is it right that prompted me? Is it right to do so? It is also possible but with prefabs?



