How to change pitch value according to plane propeller speed change?

Viewed 27

This script is attached to the plane propeller and the propeller start spinning smooth slowly to max speed.

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;
        }
    }
}

I added empty gameobject with audio source component and a script that control the pitch of the audio source component.

pitch control

what i want to do is to sync between the pitch value changes and the plane propeller speed changes.

now the plane propeller start spinning when i'm running the game and i want to use the pitch to make the sound like starting the plane engine from slowly to fast.

1 Answers

Suggestion:

I believe you are looking for:


public class AudioPitchManager : MonoBehaviour {

    public int startingPitch = 4;
    public int decreaseAmount = 5;
    private AudioSource _audioSource;

    void Start() {

        _audioSource = GetComponent<AudioSource>();
        _audioSource.pitch = startingPitch;
    }

    void Update() {

        if( _audioSource.pitch > 0 ) {
            _audioSource.pitch -= Time.deltaTime * startingPitch / decreaseAmount;
        }
    }
}

AudioSource.Pitch is used to change pitch of any audio source as you want...

Hope it helps... Happy Coding :)

Related