반응형
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);
}
}
반응형
'유니티 > 프로그래밍' 카테고리의 다른 글
[Unity] Quaternion.Lerp (회전보간) 이 끝났는지 확인하기 (1) | 2019.07.17 |
---|---|
[Unity] AudioSource 사운드 재생 갯수 제한두기 (0) | 2019.07.11 |
[Unity] Texture2D Resize하기 (크기조정) (0) | 2019.05.07 |
[Unity] 카메라흔들기 (3인칭) (0) | 2019.04.08 |
[Unity] Rigidbody.RigidbodyConstraints 코드제어 (0) | 2019.04.04 |