유니티/프로그래밍
[Unity] 파티클 타겟지점으로 움직이게하기
송호정
2019. 6. 26. 12:36
반응형
public class particleMove : MonoBehaviour {
ParticleSystem ps;
ParticleSystem.Particle[] m_Particles;
public Transform target;
public float speed = 5f;
private int numParticlesAlive;
private float step = 0;
void Start () {
ps = GetComponent<ParticleSystem>();
if (!GetComponent<Transform>()){
GetComponent<Transform>();
}
}
public void InitAttractorMove( Transform _target)
{
target = _target;
step = 0;
distance = 0;
}
void Update ()
{
if(m_Particles == null)
m_Particles = new ParticleSystem.Particle[ps.main.maxParticles];
numParticlesAlive = ps.GetParticles(m_Particles);
step = speed * Time.deltaTime;
for (int i = 0; i < numParticlesAlive; i++)
{
m_Particles[i].position = Vector3.MoveTowards(m_Particles[i].position, target.position, step);
}
ps.SetParticles(m_Particles, numParticlesAlive);
}
}
반응형