簡體   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