Unity5での衝突判定後にParticleSystemだけを残してオブジェクトを消す方法
「Unity5でのPrefabに設定したParticlelSystemをスクリプトで起動する方法」に引き続き、衝突判定後に Particle System だけを残してオブジェクトを消す方法です。
「Unity5でのPrefabに設定したParticlelSystemをスクリプトで起動する方法」のソースコードを流用して、機能を追加していきます。
といっても、単純に Particle System の起動後に、Prefab に設定してある Material の Alpha を 0 にするだけです。
public class CubeControlScript : MonoBehaviour
{
private ParticleSystem particle;
// Use this for initialization
void Start ()
{
particle = this.GetComponent<ParticleSystem> ();
// ここで Particle System を停止する.
particle.Stop ();
}
void OnTriggerEnter (Collider col)
{
// ここで Particle System を開始します.
particle.Play ();
// Material の Alpha を 0 にします.
{
// Mesh Renderer の Material を消す場合.
Material material = gameObject.GetComponent<MeshRenderer> ().material;
Color color = new Color (material.color.r, material.color.g, material.color.b, 0.0F);
gameObject.GetComponent<MeshRenderer> ().material.color = color;
}
{
// Material を消す場合.
Material material = gameObject.GetComponent<Material> ();
Color color = new Color (material.color.r, material.color.g, material.color.b, 0.0F);
gameObject.GetComponent<Material> ().color = color;
}
}
}
これで、Particle System だけを残して、オブジェクトを消すことができます。
おしまい



ディスカッション
コメント一覧
まだ、コメントがありません