When I kill my enemy some kind of gold get out of him. This gold moves forward to the player if he gets close. It moves very slow. It becomes more faster when get close to the player.
using UnityEngine;
using System.Collections;
public class souls : MonoBehaviour {
[SerializeField]
public Transform _attractorTransform;
private float paticlesFarFrom;
private ParticleSystem _particleSystem;
private ParticleSystem.Particle[] _particles = new ParticleSystem.Particle[1000];
void Start ()
{
_particleSystem = GetComponent<ParticleSystem> ();
}
public void Update()
{
if (GetComponent<ParticleSystem>().isPlaying) {
int length = _particleSystem.GetParticles (_particles);
Vector3 attractorPosition = _attractorTransform.position;
for (int i=0; i < length; i++) {
paticlesFarFrom = Vector3.Distance(_particles[i].position,_attractorTransform.transform.position);
if (paticlesFarFrom <=200) {
_particles [i].position = _particles [i].position + (attractorPosition - _particles [i].position) / (_particles [i].remainingLifetime) * Time.deltaTime;
}
}
_particleSystem.SetParticles (_particles, length);
}
}
}



