using UnityEngine;
public class StaminaMonitor : MonoBehaviour
{
public Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion m_CharacterLocomotion;
public string m_AttributeText = "Stamina";
private Opsive.UltimateCharacterController.Traits.AttributeManager m_AttributeManager;
private Opsive.UltimateCharacterController.Character.Abilities.SpeedChange m_SpeedChange;
private void Awake()
{
if (m_CharacterLocomotion == null)
{
Debug.LogError("ERROR: set 'm_CharacterLocomotion' in the inspector.");
return;
}
m_AttributeManager = GetComponent<Opsive.UltimateCharacterController.Traits.AttributeManager>();
if (m_AttributeManager == null)
{
Debug.LogError("ERROR: 'm_AttributeManager' not found.");
}
}
private void Start()
{
Opsive.UltimateCharacterController.Events.EventHandler.RegisterEvent<Opsive.UltimateCharacterController.Traits.Attribute>(m_CharacterLocomotion.gameObject, "OnAttributeUpdateValue", OnAttributeUpdateValue);
m_SpeedChange = m_CharacterLocomotion.GetAbility<Opsive.UltimateCharacterController.Character.Abilities.SpeedChange>();
if (m_SpeedChange == null)
{
Debug.LogError("ERROR: 'm_SpeedChange' not found.");
}
}
private void OnDestroy()
{
Opsive.UltimateCharacterController.Events.EventHandler.UnregisterEvent<Opsive.UltimateCharacterController.Traits.Attribute>(m_CharacterLocomotion.gameObject, "OnAttributeUpdateValue", OnAttributeUpdateValue);
}
/// <summary>
/// Monitor the "Staminia" attribute.
/// </summary>
private void OnAttributeUpdateValue(Opsive.UltimateCharacterController.Traits.Attribute attribute)
{
// ignore other attributes, IE health, shield
if (attribute.Name != m_AttributeText) return;
// if Stamina reaches 0 and 'Speed Change' is enabled - disable it
if (attribute.Value == 0 && m_SpeedChange.Enabled)
{
m_SpeedChange.Enabled = false;
}
// if 'Speed Change' is disabled and Stamina reaches 100 - enable Speed Change
if (!m_SpeedChange.Enabled && attribute.Value == 100)
{
m_SpeedChange.Enabled = true;
}
}
}
return m_Value + valueChange > m_MinValue;
That's correct - there aren't any callbacks when a certain value is reached but it is a good ideaFrom what I see there is no way to say "do something" when an attribute is a specific value.
The attribute manager will update the value after the interval specified. I can see there being a slightly on again off again situation where the attribute hits 0, increases a tiny bit, then gets used again immediately with the character starting to sprint. Even if there was a slight delay when the attribute increased this wouldn't prevent this situation so I'd like to figure out a different way to handle it. Maybe two values, a min value and then one that specifies a min starting value? So the character will stop sprinting when the attribute reaches 0, but then not be able to start again until the attribute reaches x?This works but the only thing is when it goes down to 0 the stamina increases straight away. is there a way to make it wait a certain amount of time before it increases.
The attribute manager will update the value after the interval specified. I can see there being a slightly on again off again situation where the attribute hits 0, increases a tiny bit, then gets used again immediately with the character starting to sprint. Even if there was a slight delay when the attribute increased this wouldn't prevent this situation so I'd like to figure out a different way to handle it. Maybe two values, a min value and then one that specifies a min starting value? So the character will stop sprinting when the attribute reaches 0, but then not be able to start again until the attribute reaches x?
i'd change the values to increase slower based on the amount of time you want it to reach 100. although, I'm biased since my attribute stuff is all time based.
edit: +1 for the callback idea! it'd be nice to have the ability to not have to code anything. ie bolt/playmaker
I'm still not sure of the correct route to take. Using @devomage's idea you could just have the attribute increase in value with more of a delay so in that case you wouldn't need the new min value.Will there be an update which fixes this?
Thanks for letting me know - this is a problem with the way the attributes are checking the minimum value. Within Attribute.IsValid change the >= to > on line 143 of AttributeManager.cs.
Code:return m_Value + valueChange > m_MinValue;
That's correct - there aren't any callbacks when a certain value is reached but it is a good idea
Hi, this should have been fixed with the latest version, so if you haven't updated yet please do soHello! Looks like this has not been changed in code.
Is this still considered a bug?