从检查点加载后如何禁用动画师
how to disable animator after load in from checkpoint
因此,对于某些情况,我制作了一个在 52 秒后加载的健康栏(等待 52 秒,然后从 0 健康变为 100 健康),现在我也制作了检查点。两者都可以单独工作,但是当我死后,健康栏动画会重置,我必须等待 52 秒才能看到健康栏。我尝试在您死亡并在检查点重生时禁用动画师,但这不起作用,因为它被我的健康栏脚本覆盖了。这是我的健康栏脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Healthbar : MonoBehaviour
{
[SerializeField] private Slider slider;
[SerializeField] private Animator anim;
private float Waittime = 52f;
public GameObject player;
public void SetMaxHealth(int health)
{
slider.maxValue = health;
slider.value = health;
}
public void SetHealth(int health)
{
slider.value = health;
}
private void Update()
{
if (Waittime <= 0)
{
anim.enabled = false;
}
else
{
Waittime -= Time.deltaTime;
anim.enabled = true;
}
}
}
这是我在玩家从检查点重生后禁用动画师的尝试(可能有帮助):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class healthafter : MonoBehaviour
{
// Start is called before the first frame update
private GameMaster GM;
public Animator anim;
void Start()
{
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
transform.position = GM.lastCheckpointPos;
anim.enabled = false;
}
}
如何在玩家从检查点重生后禁用动画?
此代码可以改进...但是对于您当前的情况,您还必须重置 waitTime 变量。所以你在 heathafter 脚本中的启动函数应该是这样的。
public HealthBar healthbar;
void Start()
{
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
transform.position = GM.lastCheckpointPos;
anim.enabled = false;
healthbar.ResetWaitTime(); // this will call ResetWaitTime method from your healthbar script
}
将此添加到您的 HealthBar 脚本中
public void ResetWaitTime(){
Waittime =52;
}
我通过引用检查点脚本中的 waittime 变量(有 52 秒并等待动画加载的变量)修复了它。然后我说如果标签是== player,WaiTime = 0f
因此,对于某些情况,我制作了一个在 52 秒后加载的健康栏(等待 52 秒,然后从 0 健康变为 100 健康),现在我也制作了检查点。两者都可以单独工作,但是当我死后,健康栏动画会重置,我必须等待 52 秒才能看到健康栏。我尝试在您死亡并在检查点重生时禁用动画师,但这不起作用,因为它被我的健康栏脚本覆盖了。这是我的健康栏脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Healthbar : MonoBehaviour
{
[SerializeField] private Slider slider;
[SerializeField] private Animator anim;
private float Waittime = 52f;
public GameObject player;
public void SetMaxHealth(int health)
{
slider.maxValue = health;
slider.value = health;
}
public void SetHealth(int health)
{
slider.value = health;
}
private void Update()
{
if (Waittime <= 0)
{
anim.enabled = false;
}
else
{
Waittime -= Time.deltaTime;
anim.enabled = true;
}
}
}
这是我在玩家从检查点重生后禁用动画师的尝试(可能有帮助):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class healthafter : MonoBehaviour
{
// Start is called before the first frame update
private GameMaster GM;
public Animator anim;
void Start()
{
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
transform.position = GM.lastCheckpointPos;
anim.enabled = false;
}
}
如何在玩家从检查点重生后禁用动画?
此代码可以改进...但是对于您当前的情况,您还必须重置 waitTime 变量。所以你在 heathafter 脚本中的启动函数应该是这样的。
public HealthBar healthbar;
void Start()
{
GM = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
transform.position = GM.lastCheckpointPos;
anim.enabled = false;
healthbar.ResetWaitTime(); // this will call ResetWaitTime method from your healthbar script
}
将此添加到您的 HealthBar 脚本中
public void ResetWaitTime(){
Waittime =52;
}
我通过引用检查点脚本中的 waittime 变量(有 52 秒并等待动画加载的变量)修复了它。然后我说如果标签是== player,WaiTime = 0f