Here a small script for using a hit indicator as a crosshair Addition... implemented in style of the crosshair monitor
Hope someone can use it....
cheers
Code:
public class CrossHairAdditions : CharacterMonitor
{
public Image _hitIndicator_top;
public Image _hitIndicator_left;
public Image _hitIndicator_right;
public Image _hitIndicator_bottom;
[Tooltip("Should the hitindicator be shown?")]
[SerializeField] protected bool m_ShowCrosshairHitIndicator = true;
[SerializeField] protected Color m_DefaultColor = Color.white;
[Tooltip("The color of the hitindicator when a target is hit.")]
[SerializeField] protected Color m_TargetColor = Color.red;
public ScheduledEventBase m_ScheduledFadeEvent;
/// <summary>
/// Initialize the default values.
/// </summary>
protected override void Awake()
{
base.Awake();
m_GameObject = gameObject;
}
/// <summary>
/// Attaches the monitor to the specified character.
/// </summary>
/// <param name="character">The character to attach the monitor to.</param>
protected override void OnAttachCharacter(GameObject character)
{
if (m_Character != null)
{
EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, Collider>(m_Character, "OnHitEnemy", OnHitEnemy);
}
base.OnAttachCharacter(character);
if (m_Character == null)
{
return;
}
_hitIndicator_top.color =m_TargetColor ;
_hitIndicator_left.color=m_TargetColor ;
_hitIndicator_right.color=m_TargetColor ;
_hitIndicator_bottom.color=m_TargetColor ;
EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, Collider>(m_Character, "OnHitEnemy", OnHitEnemy);
}
void OnHitEnemy(float amount, Vector3 pos, Vector3 dir, GameObject obj, Collider col)
{
if(!m_ShowCrosshairHitIndicator)return;
_hitIndicator_top.gameObject.SetActive(true);
_hitIndicator_left.gameObject.SetActive(true);
_hitIndicator_right.gameObject.SetActive(true);
_hitIndicator_bottom.gameObject.SetActive(true);
m_ScheduledFadeEvent = Scheduler.Schedule(0.5f, fadeHitindicator);
}
void fadeHitindicator(){
_hitIndicator_top.gameObject.SetActive(false);
_hitIndicator_left.gameObject.SetActive(false);
_hitIndicator_right.gameObject.SetActive(false);
_hitIndicator_bottom.gameObject.SetActive(false);
}
}
cheers