I’m still somewhat of a beginner, but I’m trying to figure out how to make this work and I cannot seem to find anything quite like what I’m looking for.
The idea of this script is that when the HP bar appears when the player is hit. That works as the hitState is activated. The problem is it never deactivates. I’ve tried adding a timer via WaitForSeconds and trying to have it switch back off. However, it tells me that on line 44 that the best overloaded math for StartCoroutine has some invalid arguments. The second error is also on line 44 as it says argument #1 cannot covert ‘method’ group’ expression to type ‘System.Collections.IEnumerator’
I am aware the code looks a bit weird as it’s also finding another component from another script. Pretty much the clampTag only serves to pin the HP bar UI above the player’s head at all times. The below is the script in question.
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HpBarBehavior : MonoBehaviour
{
public Image UiTag;
public bool hitState = false;
public float fadeTime;
public float fadeInstruction;
private const float BarFadeDuration = 1.0f;//time tofade in/out the bar
private float _fadeTimer = 0.0f;
private float timeSinceLastCombat = 10000.0f;
private const float CombatTimeout = 1.0f;//how long till no incombats starts a fadeout. so that things dont bounce on/off too much
private float barTimer = 0.0f;
private float barAlpha = 0.0f;
void Start()
{
if (hitState == false)
{
UiTag.gameObject.SetActive(false);
GameObject.Find("ThirdPersonController").GetComponent<PlayerHealth>();
GameObject.Find("tagHolder").GetComponent<ClampTag>();
}
}
public void inCombat()// call at start of, while still in combat
{
timeSinceLastCombat = 0.0f;
}
// Update is called once per frame
public void Update()
{
if (hitState == true)
{
UiTag.gameObject.SetActive(true);
GameObject.Find("ThirdPersonController").GetComponent<PlayerHealth>();
GameObject.Find("tagHolder").GetComponent<ClampTag>();
StartCoroutine(timerCount);
}
}
public void OnCollisionEnter(Collision collision)
{
Debug.Log(collision.gameObject.tag);
if (collision.gameObject.tag == "Hit")
{
hitState = true;
}
}
IEnumerator timerCount()
{
yield return new WaitForSeconds(5);
UiTag.gameObject.SetActive(false);
GameObject.Find("ThirdPersonController").GetComponent<PlayerHealth>();
GameObject.Find("tagHolder").GetComponent<ClampTag>();
}
}