プレーヤーが動いているときや、プレーヤーがボールのように動いているときに、いくつかのサウンドがあります。私たちはボールの動きが速くなるほど、音の高さを上げたいと思っています。私は以下のコードを試しましたが、何もしません。私は、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