首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何根据飞机螺旋桨转速的变化来改变螺距值?

如何根据飞机螺旋桨转速的变化来改变螺距值?
EN

Stack Overflow用户
提问于 2022-09-07 03:46:24
回答 1查看 30关注 0票数 -1

这个脚本是附加到平面螺旋桨和螺旋桨开始旋转平稳到最大的速度。

代码语言:javascript
复制
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;
        }
    }
}

我添加了带有音频源组件的空游戏对象和控制音频源组件音调的脚本。

我想要做的是同步之间的螺距值变化和飞机螺旋桨的速度变化。

现在,当我运行游戏的时候,飞机螺旋桨开始旋转,我想用这个音高来发出像启动飞机引擎这样的声音,从慢到快。

EN

回答 1

Stack Overflow用户

发布于 2022-09-07 04:25:32

建议:

我相信你是在寻找:

代码语言:javascript
复制
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被用来改变任何音频源的音高,只要你愿意.

希望能帮上忙..。快乐编码:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73629906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档