【发布时间】:2017-02-26 21:33:04
【问题描述】:
我的代码有问题。当我按下分配的键码“Z”时,CurrentState 不会更改为 1 并继续执行整个组合。我尝试放置一个 debug.log,发现盒子碰撞器在按下 Z 时会激活,但数字不会增加 1。有人可以帮帮我吗?这是代码。
公共类斗士: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]);
}
}
}
}
【问题讨论】: