简体   繁体   中英

unity 3d - particle system

I am really new to programming and super new using unity xD I am trying to make a little game myself (2D). I need some help configuring the particle system.

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 () {

     }
}

The problem is that i don't know how to implement a code to stop the particle emission if the button is not pressed. I tried with an if statement but i get an error tolding me to check if the particle system is attached to the gameobject. Thanks for help in advance :)

Instead of Input.getButton, use Input.getButtonDown, this will check to see if the button is pressed.

Then change your if statement to the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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