Unity Harvesting

Introduction

The HarvestableObject is a class in the Unity game engine that represents an object that can be harvested by the player or other entities in the game. It contains a variety of properties and methods that allow it to be customized and interacted with in different ways.

HarvestableObjects can be configured with a range of different harvestable components, such as HarvestableChildren and HarvestableColliders, which can be used to define the specific parts of the object that can be harvested. The HarvestableMask can also be used to define the specific areas of the object that can be harvested.

The HarvestableObject class also contains a number of properties that define its appearance, behavior, and interaction with the game world. These include its mesh, materials, health, and various audio and visual effects that can be triggered when the object is harvested.

In addition to its properties, the HarvestableObject class also includes a number of methods that allow it to be interacted with by other game objects. For example, the OnHarvested method is called when the object is harvested, allowing it to trigger any relevant effects or events.

Overall, the HarvestableObject class is a versatile and powerful tool for game developers looking to add dynamic and customizable harvesting mechanics to their games.

Overview page:

HarvestableObject is a C# script that is used to define the properties and behavior of harvestable objects in a Unity game. It defines the health and regeneration of the object, how it can be damaged by tools, and the number of child objects that can be spawned or despawned based on the object’s health.

Interface pages:

None

Constructor pages:

None

Method pages:

Method Description
Awake() Called when the script instance is being loaded.
Heal() Used to regenerate the health of the object.
Start() Called before the first frame update.
OnMouseOver() Called when the mouse is over the object.
Update() Called once per frame.
AlignCamera() Aligns the object to the main camera.
UpdateUi(float maxHealth, float curHealth) Updates the health bar UI.
DestroySelf() Destroys the object.
HandleChildren() Handles the spawning and despawning of child objects based on the object’s health.
RandomObject(List<HarvestableChild> thisChild2) Returns a random child object from a list.
RandomObject2(List<HarvestableChild> thisChild2) Returns a random inactive child object from a list.
spawnChild() Spawns a child object.
despawnChild() Despawns a child object.

 

Modifier and Type Property Description
public bool enableHealthUI Enable the health UI on the Vegetation objects.
public bool enableRegen Enable the vegetation object the ability to regenerate health.
public float harvestableHealth The health that the harvestable object currently has.
public float maxHealth The maximum health that the harvestable object has.
public float healthBarLength How long the healthbar is.
public float healTime The time that is required to heal the object.
public float lerp This is the amount of health regen that is currently occuring.
public float smoothing The amount of smoothing applied to the healing, this is to cap the ups and downs of the health flow.
public GameObject healthBar The healthbar UI object.
public Vector3 healthBarOffset The offset for the healthbar UI object.
public int recoveryTickRate The number of tickets that must pass before healing itself.
public float recoveryPerTick The amount of recovery per tick. Low values are harder to approximate, if you want it to heal slow increase the recoveryTickRate above in addition to this.
public int terrainIndex The terrain index of the harvestable object.
public bool enableChildren Whether or not the harvestable object has children.
public List<HarvestableChild> HarvestableObjectChildren A list of the harvestable object’s children.
public int childPerHealth The number of children per health.
public int numberofChildren The number of children of the harvestable object.
public List<string> toolType The tag of the tool that can damage this harvestable object.
public List<string> damageToolType The tag of the tool to start damaging. Todo.
public List<string> weakToolType The tag of the tool to start damaging. Todo.
public int damageToTool The amount of damage this object will do to the tool.
public float damageToToolMultiplier The amount of damage multiplied this object will do to the tool.
public float harvestingRestoreTime The time it takes for the tree to grow back.
public int skillLevelRequired The skill level required to harvest the object.