I know this question has been answered many times before, but I still can’t manage to get my script to work. I’m developing a CPR game and every time the space bar is pressed, it should trigger the hand compression animation. I set all my loops to off and I have an idle state. Sorry for the large block of code, line 13 is where it’s triggered.
void Update()
{
if (Tempo.activeSelf)
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (check == false)
{
StartCoroutine(bpmTimer());
check = true;
}
countCompressions--;
compressionAnim.Play("HandCompressionAnimation");
if (countCompressions > 0)
{
Debug.Log("Counting compressions");
}
if (countCompressions <= 0)
{
StopAllCoroutines();
if (openWindow == true && endTempoPanel == false)
{
Debug.Log("Correct bpm");
endTempoPanel = true;
Tempo.SetActive(false);
HandAnimation.SetActive(false);
RescueBreaths.SetActive(true);
}
else if (tooFast == true && endTempoPanel == false)
{
Debug.Log("Too fast");
endTempoPanel = true;
Tempo.SetActive(false);
HandAnimation.SetActive(false);
FailureToCompressFast.SetActive(true);
}
else if (tooSlow == true && endTempoPanel == false)
{
Debug.Log("Too slow");
endTempoPanel = true;
Tempo.SetActive(false);
HandAnimation.SetActive(false);
FailureToCompressSlow.SetActive(true);
}
}
}
else
{
compressionAnim.Play("Idle");
}
}
GameObject HeadAreaTrigger = GameObject.Find("HeadAreaTrigger");
TriggerAreaScript triggerAreaScript = HeadAreaTrigger.GetComponent<TriggerAreaScript>();
//triggerArea1 = triggerAreaScript.triggerArea;
if (triggerAreaScript.triggerArea == true && checkedVitals == false)
{
Debug.Log("Calling checked vitals function");
onCheckedVitals();
checkedVitals = true;
}
}