【问题标题】:Properly play Particule System component?正确播放粒子系统组件?
【发布时间】:2015-12-25 07:26:42
【问题描述】:

如何正确播放附加到游戏对象的粒子系统组件?我还将以下脚本附加到我的游戏对象,但粒子系统不播放。我该如何解决这个问题?

public Transform gameobject1;
public Transform gameobject2;
public ParticleSystem particules;

void Start()
{
    float distance = Vector3.Distance(gameobject1.position, gameobject2.position);
}

void Update()
{
    if(distance == 20)
  {
      particules.Play();
  }
}

【问题讨论】:

  • @Micky 在我的情况下不是。我编辑了问题。
  • 啊,是的。谢谢迪米特里
  • @Micky 我更详细地编辑了这个问题。

标签: c# unity3d particles particle-system unity5


【解决方案1】:

假设这是您编写的确切代码,您需要首先使用GetComponent方法才能在您的粒子系统上执行操作

您的代码应如下所示:

public Transform gameobject1;
public Transform gameobject2;
public ParticleSystem particules;
public float distance;

//We grab the particle system in the start function
void Start()
{
    particules = GetComponent<ParticleSystem>();
}

void Update()
{
    //You have to keep checking for the Distance
    //if you want the particle system to play the moment distance goes below 20 
    //so we set our distance variable in the Update function.
    distance = Vector3.Distance(gameobject1.position, gameobject2.position);

    //if the objects are getting far from each other , use (distance >= 20)
    if(distance <= 20) 
    {
        particules.Play();
    }
}

【讨论】:

    【解决方案2】:

    我没有看到你在课堂上声明距离,但你在更新时使用它。将距离声明为与您的其他成员的私人浮动,并在开始时定义它。

    假设您的代码不完全是这样,您的问题看起来也源于使用带距离的固定值。尝试使用小于或等于 20。

    if(distance &lt;= 20)

    或者你可以尝试大于 19 小于 21。

    if(distance &lt;= 21 &amp;&amp; distance &gt;= 19)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      相关资源
      最近更新 更多