速度に応じて車の音程を変更する必要があります。現在、私は答えの解決策を使用しています: https://answers.unity.com/questions/1067016/car-engine-sound-code-unity5car-engine-sound-code.html
public float topSpeed = 100; // km per hour
private float currentSpeed = 0;
private float pitch = 0;
void Update ()
{
currentSpeed = transform.GetComponent<Rigidbody>().velocity.magnitude * 3.6f;
pitch = currentSpeed / topSpeed;
transform.GetComponent <AudioSource> ().Pitch = pitch;
}
これによると、開始pitch
は0
私のcurrentSpeed
Ieに従って変化します- currentSpeed
/topSpeed
私の現在speed = topSpeed
の場合pitch
はそうなり1
、それは良いアプローチですが、私の場合は音を再生しますが、車が到達topSpeed
すると音の再生を停止し、二度と再生しませんブレーキをかけてゼロスピードから発進しても
私は初中級者なので、車の剛体がキネマティックであるためだと思いますが、正しい理由と解決策はわかりません。