【发布时间】:2021-08-22 22:16:38
【问题描述】:
我正在尝试为这个 healthkit 制作动画,但由于某种原因它没有。我通过添加 debug.log 对其进行了测试,当我按 Q 时,我收到错误“对象引用未设置为对象的实例”。我不知道它为什么会这样做。感谢您的帮助!
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;
}
}
【问题讨论】: