繁体   English   中英

UNITY-攻击命中组合代码错误。 需要帮助

[英]UNITY - Attack Hit Combo Code Error. Help needed

我的代码有问题。 当我按下分配的键码“ Z”时,CurrentState不会更改为1,而是继续执行整个组合。 我尝试放入debug.log,发现按Z时确实激活了盒碰撞器,但数字却没有增加1。有人可以帮我吗? 这是代码。

公共课Fighter:MonoBehaviour {

public Collider[] attackhitboxes;
public Animator art;
public int CurrentState = 0;
bool activateTimertoreset = false;
public float currentcombotimer;
float origTimer = 50f;
private void Start()
{
    art = gameObject.GetComponent<Animator>();
    origTimer = currentcombotimer;
}
void Update()
{
    art.SetInteger("currentstate", CurrentState);
    NewComboSystem();
    ResetComboState(activateTimertoreset);

}

void ResetComboState(bool resettimer)
{
    if(resettimer)
    {
        currentcombotimer -= Time.deltaTime;

        if(currentcombotimer <= 0)
        {
            CurrentState = 0;
            activateTimertoreset = false;
            currentcombotimer = origTimer;
        }
    }
}
    private void LaunchAttack(Collider col)
{
    Collider[] cols = Physics.OverlapBox(col.bounds.center, col.bounds.extents, col.transform.rotation, LayerMask.GetMask("Hitbox"));
    foreach(Collider c in cols)
    {
        if(c.transform.parent.parent == transform)
        {
            continue;
        }
    }
}

void NewComboSystem()
{
    if (Input.GetKeyDown(KeyCode.Z))
    {
        activateTimertoreset = true;
        CurrentState++;
        if (CurrentState == 1)
        {
            LaunchAttack(attackhitboxes[0]); 
        }

        if (CurrentState == 2)
        {
            LaunchAttack(attackhitboxes[0]);
        }

        if (CurrentState >= 3)
        {
            LaunchAttack(attackhitboxes[0]);
        }
    }
}

}

尝试将您的if(input.keydown)放在更新函数中,然后将其称为攻击。 有了它,我相信它每秒都会多次调用您的攻击功能,因为更新会在每个帧中运行。 同时尝试调试currentstate的值。

编辑:由于它是公共的,您是否正在编辑器中为currentcombotimer分配一个值? 在脚本中,它没有起始值。 在启动功能中,将其分配给origTimer。 如果该值为零,则您的组合时间为零。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM