【问题标题】:unity 3d - particle systemunity 3d - 粒子系统
【发布时间】:2015-02-07 10:04:18
【问题描述】:

我对编程非常陌生,并且使用 unity 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 语句,但我收到一个错误,告诉我检查粒子系统是否附加到游戏对象。提前感谢您的帮助:)

【问题讨论】:

    标签: c# unity3d particle-system particles


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多