[英]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). 我真的是编程新手,并且使用unity xD超级新手,我想自己做一个小游戏(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. 我尝试了一个if语句,但遇到一个错误,告诉我检查粒子系统是否已连接到游戏对象。 Thanks for help in advance :) 预先感谢您的帮助:)
Instead of Input.getButton, use Input.getButtonDown, this will check to see if the button is pressed. 使用Input.getButtonDown代替Input.getButton,这将检查按钮是否被按下。
Then change your if statement to the following: 然后将if语句更改为以下内容:
if (engineActive)
{
rigidbody2D.AddForce(new Vector2(0, charForce));
} else {
//run code here for when button is not pressed.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.