私の目標は、特定の期間衝突したオブジェクトの移動速度を低下させる単一の衝突検出を行うことです。私がこれまで試したどのようなbuff/unbuffへの再帰呼び出し? C#Unity3D
:
//Class that detects the collision
if (other.gameObject.tag == "enemy")
{
EnemyMovement enemyMove = other.GetComponent <EnemyMovement>();
if (enemyMove.slowMove != 1) {
return;
}
enemyMove.Slow (2, 0.5f, true);
//....
//Class that handles the Enemy-Movement
//The slowfactor gets multiplied with the Vector3 that handles the movementspeed of the Character
void FixedUpdate()
{
Movement();
}
void Movement()
{
gegnerRigid.MovePosition (transform.position + (gegnerMove * slowMove));
}
public void Slow (float duration, float slowFactor, bool slowed)
{
if (slowed)
{
if (duration > 0) {
duration -= Time.deltaTime;
slowMove = slowFactor;
Slow (duration, slowFactor, slowed); //this recursive Call leads to huge performance issues, but how to keep the function going?
} else {
slowMove = 1;
slowed = false;
}
}
}
だから私が起こることを望ん: は、衝突が発生した場合にスロー関数を呼び出すと持続時間が0
これは非常に間違っています。あなたはUnity3Dのタイマーのために** Invoke **を使用します。 – Fattie
**決して**再帰を使用することは決してありません。 – Fattie
@JoeBlowはInvokeRepeatingを使用しない方が良いでしょうか? –