「Unity/Csharp/Particle」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==パーティクル再生== GameObject gameObj = GameObject.Find ("ParticleSystem1"); gameObj.GetComponent<ParticleSystem> ().Stop (); ==パーティクル停止== G...」) |
(→オーラとか) |
||
(同じ利用者による、間の4版が非表示) | |||
行6: | 行6: | ||
GameObject gameObj = GameObject.Find("ParticleSystem1"); | GameObject gameObj = GameObject.Find("ParticleSystem1"); | ||
gameObj.GetComponent<ParticleSystem> ().Play (); | gameObj.GetComponent<ParticleSystem> ().Play (); | ||
+ | |||
+ | ==ホーミングレーザーを作る== | ||
+ | 追跡弾を2つ作ってみる例 | ||
+ | |||
+ | #UI/Particle Systemを新規で作る。 | ||
+ | #"Particle System"というのと"Particle System2"というのを作る。 | ||
+ | <pre> | ||
+ | |||
+ | public class HomingScene : MonoBehaviour | ||
+ | { | ||
+ | ParticleSystem ps; | ||
+ | ParticleSystem ps2; | ||
+ | ParticleSystem.Particle[] m_Particles; | ||
+ | public float threshold = 1f; | ||
+ | public float intensity = 1f; | ||
+ | public Transform target; | ||
+ | |||
+ | public float _speed = 0.01f; // 1秒間に進む距離 | ||
+ | public float _rotSpeed = 180.0f; // 1秒間に回転する角度 | ||
+ | void Start() | ||
+ | { | ||
+ | ps = GameObject.Find("Particle System").GetComponent<ParticleSystem>(); | ||
+ | ps2 = GameObject.Find("Particle System2").GetComponent<ParticleSystem>(); | ||
+ | target = GameObject.Find("CircleSprite").transform; | ||
+ | } | ||
+ | void Update() | ||
+ | { | ||
+ | ViewParticle(ps); | ||
+ | ViewParticle(ps2); | ||
+ | } | ||
+ | void ViewParticle(ParticleSystem ps) | ||
+ | { | ||
+ | m_Particles = new ParticleSystem.Particle[ps.main.maxParticles]; | ||
+ | int numParticlesAlive = ps.GetParticles(m_Particles); | ||
+ | for (int i = 0; i < numParticlesAlive; i++) | ||
+ | { | ||
+ | var forward = ps.transform.TransformPoint(m_Particles[i].velocity); | ||
+ | var position = ps.transform.TransformPoint(m_Particles[i].position); | ||
+ | var direction = (target.TransformPoint(target.position) - position).normalized; | ||
+ | var period = 1 - (m_Particles[i].remainingLifetime / m_Particles[i].startLifetime); | ||
+ | m_Particles[i].velocity = ps.transform.InverseTransformPoint(forward + direction * period); | ||
+ | } | ||
+ | ps.SetParticles(m_Particles, numParticlesAlive); | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | 参考:https://qiita.com/Shinoda_Naoki/items/c6fbfc85fe24b2fcd5a1 | ||
+ | |||
+ | ブラーとかは?参考になる? https://baba-s.hatenablog.com/entry/2018/04/10/094300 | ||
+ | |||
+ | ==オーラとか== | ||
+ | http://ktk-kumamoto.hatenablog.com/entry/2014/09/28/080827 | ||
+ | |||
+ | ==unity公式パーティクル パック== | ||
+ | https://assetstore.unity.com/packages/essentials/tutorial-projects/unity-particle-pack-127325?utm_source=youtube&utm_medium=social&utm_campaign=education_global_generalpromo_2018-09-04_particle-pack&utm_content=download_video |
2020年6月26日 (金) 20:54時点における版
パーティクル再生
GameObject gameObj = GameObject.Find ("ParticleSystem1"); gameObj.GetComponent<ParticleSystem> ().Stop ();
パーティクル停止
GameObject gameObj = GameObject.Find("ParticleSystem1"); gameObj.GetComponent<ParticleSystem> ().Play ();
ホーミングレーザーを作る
追跡弾を2つ作ってみる例
- UI/Particle Systemを新規で作る。
- "Particle System"というのと"Particle System2"というのを作る。
public class HomingScene : MonoBehaviour { ParticleSystem ps; ParticleSystem ps2; ParticleSystem.Particle[] m_Particles; public float threshold = 1f; public float intensity = 1f; public Transform target; public float _speed = 0.01f; // 1秒間に進む距離 public float _rotSpeed = 180.0f; // 1秒間に回転する角度 void Start() { ps = GameObject.Find("Particle System").GetComponent<ParticleSystem>(); ps2 = GameObject.Find("Particle System2").GetComponent<ParticleSystem>(); target = GameObject.Find("CircleSprite").transform; } void Update() { ViewParticle(ps); ViewParticle(ps2); } void ViewParticle(ParticleSystem ps) { m_Particles = new ParticleSystem.Particle[ps.main.maxParticles]; int numParticlesAlive = ps.GetParticles(m_Particles); for (int i = 0; i < numParticlesAlive; i++) { var forward = ps.transform.TransformPoint(m_Particles[i].velocity); var position = ps.transform.TransformPoint(m_Particles[i].position); var direction = (target.TransformPoint(target.position) - position).normalized; var period = 1 - (m_Particles[i].remainingLifetime / m_Particles[i].startLifetime); m_Particles[i].velocity = ps.transform.InverseTransformPoint(forward + direction * period); } ps.SetParticles(m_Particles, numParticlesAlive); } }
参考:https://qiita.com/Shinoda_Naoki/items/c6fbfc85fe24b2fcd5a1
ブラーとかは?参考になる? https://baba-s.hatenablog.com/entry/2018/04/10/094300
オーラとか
http://ktk-kumamoto.hatenablog.com/entry/2014/09/28/080827