简体   繁体   English

Unity - GetKeyDown 没有粒子效果

[英]Unity - No Particle Effect on GetKeyDown

I'm trying to complete one of the bonus problems for the 4th Challenge from Unity's Junior Programmer Create with Code 2 Pathway.我正在尝试完成 Unity 的初级程序员使用代码 2 路径创建的第 4 次挑战的奖励问题之一。 The instructions are "The player should get a speed boost whenever the player presses spacebar - and a particle effect should appear when they use it".说明是“每当玩家按下空格键时,玩家应该获得速度提升 - 当他们使用它时应该出现粒子效果”。 The hint is "In PlayerController, add a simple if-statement that adds an “impulse” force if spacebar is pressed. To add a particle effect, first attach it as a child object of the Focal Point."提示是“在 PlayerController 中,添加一个简单的 if 语句,如果按下空格键,它会添加一个“脉冲”力。要添加粒子效果,首先将其附加为 Focal Point 的子项 object。”

I've added the speed boost successfully, but can't get the particle effect to work.我已经成功添加了速度提升,但无法让粒子效果发挥作用。 I've attached the effect to be a child of the Focal Point, but nothing seems to be working.我已将效果附加为 Focal Point 的子级,但似乎没有任何效果。 Here is my code below.下面是我的代码。

    private Rigidbody playerRb;
    public float speed = 500f;
    private GameObject focalPoint;

    private float speedBoost = 10.0f;

    public ParticleSystem smokeParticle;
    
    void Start()
    {
        playerRb = GetComponent<Rigidbody>();
        focalPoint = GameObject.Find("Focal Point");
    }

    void Update()
    {
        // Add force to player in direction of the focal point (and camera)
        float verticalInput = Input.GetAxis("Vertical");
        playerRb.AddForce(focalPoint.transform.forward * verticalInput * speed * Time.deltaTime); 

        if (Input.GetKeyDown(KeyCode.Space))
        {
            playerRb.AddForce(focalPoint.transform.forward * speedBoost, ForceMode.Impulse);

            smokeParticle.Play();
        }
    }

Maybe try smokeParticle.Play(true);也许试试smokeParticle.Play(true); most particle have children need to be played along with it大多数粒子都有孩子需要和它一起玩

https://docs.unity3d.com/ScriptReference/ParticleSystem.Play.html https://docs.unity3d.com/ScriptReference/ParticleSystem.Play.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM