I am trying to animate this healthkit but for some reason it doesn't. I tested it by adding a debug.log and when I press Q I get the error "Object reference not set to an instance of an object". I don't know why it would do this. Thanks for the help!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Anim_Trigger_for_healthpack : MonoBehaviour
{
private Coroutine onHealKit = null;
private Animator anim;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
if (onHealKit == null)
onHealKit = StartCoroutine(HealthKit());
}
}
IEnumerator HealthKit()
{
anim.SetBool("Qpress", true); //bug on this line
yield return new WaitForSeconds(2.0f);
anim.SetBool("Qpress", false);
onHealKit = null;
}
}