當玩家移動或滾動時,我們有一些聲音是球員。我們希望增加音頻的音調,球速度越快。我嘗試了下面的代碼,但它什麼也沒做。我認爲這是因爲p的價值太小了。 我記得在某個地方看到有一些內置的東西來處理這個問題,但我想不出我看到了什麼或它被稱爲什麼。更改基於剛體速度的音頻音高
在此先感謝!
void FixedUpdate()
{
#if UNITY_EDITOR || UNITY_STANDALONE
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 move = new Vector3(-moveHorizontal, 0.0f, -moveVertical);
move = move * (speed/15f);
//maxSpeed = maxSpeed/5;
#else
// Player movement in mobile devices
// Building of force vector
Vector3 move = new Vector3(-Input.acceleration.x, 0.0f, -Input.acceleration.y);
// Adding force to rigidbody
move = move * (speed/15f);
//move = movement * speed * Time.deltaTime;
#endif
rigidbdy.AddForce(move);
var p = rigidbdy.velocity.magnitude/speed;
audio.pitch = Mathf.Clamp(p, 1.0f, 2.0f); // p is clamped to sane values
//Limits the max speed
if (rigidbdy.velocity.magnitude > maxSpeed)
{
rigidbdy.velocity = rigidbdy.velocity.normalized * maxSpeed;
}
}
謝謝。我會在今天晚些時候嘗試並報告。 – jbassking10