Unity4.2の新機能 - Shurikenでコリジョンのコールバックを作成
今までShurikenではOnParticleCollisionが動きませんでした
まず、設定を「World」にして「Send Collision Messages」にチェック
Particle SystemCubeの位置関係はこんな感じ
使う方法は二種類ある
ParticleSystem自体にスクリプトをアタッチ
using UnityEngine; using System.Collections; [RequireComponent(typeof(ParticleSystem))] public class Example : MonoBehaviour { void OnParticleCollision (GameObject other) { ParticleSystem.CollisionEvent[] ces = new ParticleSystem.CollisionEvent[particleSystem.safeCollisionEventSize]; int count = particleSystem.GetCollisionEvents (other, ces); foreach (ParticleSystem.CollisionEvent item in ces) { // action Debug.Log (item.collider); } } }
Cubeにスクリプトをアタッチ
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { void OnParticleCollision (GameObject other) { ParticleSystem shuriken = other.GetComponent<ParticleSystem>(); ParticleSystem.CollisionEvent[] ces = new ParticleSystem.CollisionEvent[shuriken.safeCollisionEventSize]; int count = shuriken.GetCollisionEvents (gameObject, ces); foreach(ParticleSystem.CollisionEvent item in ces) { // action Debug.Log (item.collider); } } }