首页 文章

统一3d - 粒子系统

提问于
浏览
0

我真的很喜欢编程和超级新的使用统一xD我试图自己制作一个小游戏(2D) . 我需要一些帮助配置粒子系统 .

using UnityEngine;
using System.Collections;

 public class CharacterController : MonoBehaviour {

     public float charForce = 75.0f;
     public float fwMvSp = 3.0f;



     void FixedUpdate () 
     {
         bool engineActive = Input.GetButton("Fire1");

         if (engineActive)
         {
             rigidbody2D.AddForce(new Vector2(0, charForce));
         }




         Vector2 newVelocity = rigidbody2D.velocity;
         newVelocity.x = fwMvSp;
         rigidbody2D.velocity = newVelocity;
     }



     // Use this for initialization
     void Start () {

     }

     // Update is called once per frame
     void Update () {

     }
}

问题是,如果没有按下按钮,我不知道如何实现代码来停止粒子发射 . 我尝试了一个if语句,但我得到一个错误,要求我检查粒子系统是否附加到游戏对象 . 在此先感谢您的帮助:)

1 回答

  • 0

    使用Input.getButtonDown代替Input.getButton,这将检查按钮是否被按下 .

    然后将if语句更改为以下内容:

    if (engineActive)
             {
                 rigidbody2D.AddForce(new Vector2(0, charForce));
             } else {
                 //run code here for when button is not pressed.
    }
    

相关问题