It's like making theI'm trying to synchronize a rotating propeller with a engine sound by changing the sound's pitch sound engine starting effect.
I have some airplane with a propeller and a script attached to the propeller making thean airplane's propeller start spinning when runningwhich, after the game starts, causes it to gradually increase rotation speed from slow to max speedmaximum.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Spin : MonoBehaviour { public float RotationSpeed = 1; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { transform.Rotate(0, 0, RotationSpeed, Space.Self); if (RotationSpeed < 10) { RotationSpeed += 1f * Time.deltaTime; } } } onOn an empty gameobject iI added audio sourcean AudioSource and dragged to it a mp3made its AudioClip an .mp3 sound effect of propeller and also attached to the empty gameobject a script and dragged to the script the propeller object with the Spin. To this gameobject I attached this script :
and a screenshot of the empty gameobject with the audio source AudioSource component:
The pitch in the audio source by default startstarts at value 1 and should be changed between the values of -3 and 3. The rotation speed in the Spin script is in other units.
what iThe behavior I want to do is when i'm running the game and: as the propeller startstarts rotating slowly and increases to max speed that, the audio source pitch automatic will automatically change it'sits value according toin sync with the propeller rotation speed so the pitch sound and the propeller rotation will be sync.
TheHowever, the script AudioExample as it is now is making the pitch value to be much over thewell exceed 3 value over, in fact it goes up to 10. The calculation in the AudioExample script is wrong and i'mI'm not sure how to docorrect it :
_audioSource.pitch += Time.deltaTime * startingPitch / spin.RotationSpeed; 
