[英]unity 3d - particle system
我真的是编程新手,并且使用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语句,但遇到一个错误,告诉我检查粒子系统是否已连接到游戏对象。 预先感谢您的帮助:)
使用Input.getButtonDown代替Input.getButton,这将检查按钮是否被按下。
然后将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.