粒子系统统一并不总是显示,统一

发布于 2025-02-07 10:09:18 字数 305 浏览 1 评论 0原文

因此,我正在尝试为我的一个小太空游戏添加粒子效果,我得到轴“垂直”,然后检查粒子系统是否大于0(向前)

flyfloat = Input.GetAxis("Vertical");
if(flyfloat > 0)
{
     particles.Play();
}
else
{
     particles.Stop();
}

控制它是否在播放粒子系统,但我遇到的问题是,它只会给出一些粒子,然后停止,我已经查看了flyfloat,它在1。

问题可能是什么?

谢谢

So I'm trying to add a particle effect to a little space game of mine, I get axis "Vertical", then check if it is greater than 0 the particle system plays (going forward)

flyfloat = Input.GetAxis("Vertical");
if(flyfloat > 0)
{
     particles.Play();
}
else
{
     particles.Stop();
}

That controls whether it is playing the particle system, but the issue i have is that it only gives some particles and then stops, I've viewed the flyfloat and it is at 1.

What may the problem be here?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清晰传感 2025-02-14 10:09:19

您的问题是不完整的,例如,我不知道您在哪里使用这些代码行。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

假设您是在update()方法中调用它。让我首先说明这里发生了什么。因此,当您按update()时,请在按下 up_arrow flyfloat = 1时,将调用每个帧。没关系,但是现在,当您进入IF循环时,检查flyfloat> 0和调用partciles.play()它被称为每个update> update()循环表示每个帧>正在播放每个帧,因此根本不玩。同样,每当您停止按下 up_arrow 键时,flyfloat = 0它在其他循环内部并停止播放preshitlesystem

因此,为了解决此问题,您可以引入一个布尔值,该布尔值partciles.play() and partciles.stop()在按下按下 up_arrow 键。

下面的代码将使pracelesystem在按 up_arrow 键时播放,并在按下 down_arrow 键时将其停止。

    public ParticleSystem particles;
    public float flyfloat;

    bool isParticlePlaying = false;


    private void Update()
    {
        flyfloat = Input.GetAxis("Vertical");

        if (flyfloat > 0  && !isParticlePlaying)
        {
            particles.Play();
            isParticlePlaying = true;
        }
        else if (flyfloat < 0 && isParticlePlaying)
        {
            particles.Stop();
            isParticlePlaying = false;
        }
    }

You question is incomplete as for example I don't know where you are using these lines of code.. inside an Update() method or a Start() method.

Assuming you are calling it in Update() method. Let me explain first what is happening wrong here. So as Update() gets called each frame when you pressing UP_Arrow key flyfloat = 1 . that's ok but now as you go inside the if loop to check flyfloat > 0 and calls partciles.Play() it is being called every Update() loop means every frame so what's happening is your ParticleSystem is getting played every frame so not playing at all. Also whenever you stops pressing the UP_Arrow key the flyfloat = 0 for which it's going inside the else loop and stops playing the ParticleSystem.

So to solve this you can introduce a Boolean which makes partciles.Play() and partciles.Stop() gets called once when you are pressing UP_Arrow key.

below code will make the ParticleSystem play when you press UP_Arrow key and stops it when you press DOWN_Arrow key

    public ParticleSystem particles;
    public float flyfloat;

    bool isParticlePlaying = false;


    private void Update()
    {
        flyfloat = Input.GetAxis("Vertical");

        if (flyfloat > 0  && !isParticlePlaying)
        {
            particles.Play();
            isParticlePlaying = true;
        }
        else if (flyfloat < 0 && isParticlePlaying)
        {
            particles.Stop();
            isParticlePlaying = false;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文