Variables Methods

v4.0

Each GameItemObject has a List<ItemObjectVariable> which contains all the variables, and the current values.

// GameItemObject.cs
public List<ItemObjectVariable> variables

// Returns the ItemObjectVariable with the variableName provided
public ItemObjectVariable Variable(string variableName)

// Note: The Variable() method will return a value that is cached in a Dictionary
// that is populated at runtime. This is more optimized for values that are called
// often. However, depending on your project, you may wish to cache the
// ItemObjectVariable in another location where it is often accessed, perhaps in
// another class.

Methods

Get Value & RangeValue

var durability = gameItemObject.Variable("Durability");

// Get the current value
var durabilityValue = durability.value;

// Get the current RangeValue
var durabilityRangeValue = durability.RangeValue;

Example

You can use the value of durability to modify the "price" of a GameItemObject.

Add Value

Use the AddValue() method to add value to the Variable. Add a negative value to subtract. The final Value will be clamped between Min and Max, and RangeValue will be updated.

Returns the RangeValue of the Variable.

Set Value

Use the SetValue() method to set the value to a specific amount. Add a negative value to subtract. The final Value will be clamped between Min and Max, and RangeValue will be updated.

Returns the RangeValue of the Variable.

You can change the values of Min and Max at runtime! While they will always start at the values set in the ItemObject scriptable object, you can modify them later for even more game mechanic opportunities.

Set to a specific RangeValue

RangeValue is always between 0f and 1f, between the Min and Max values and modified by the curve, if in use. Rather than setting the specific Value, you can opt to set a RangeValue, and the Value will be computed based on that.

Returns the Value of the Variable.

Last updated

Was this helpful?