Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ParticleTarget : MonoBehaviour {
  6.  
  7.  
  8. [SerializeField]
  9. private Transform target;
  10.  
  11. [SerializeField]
  12. private float force = 10.0f;
  13.  
  14. private ParticleSystem ps;
  15.  
  16. // Use this for initialization
  17. void Start () {
  18. ps = GetComponent<ParticleSystem>();
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23.  
  24. }
  25.  
  26. private void LateUpdate()
  27. {
  28. ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount];
  29. ps.GetParticles(particles);
  30.  
  31.  
  32.  
  33. for(int i = 0; i < particles.Length; i++)
  34. {
  35. ParticleSystem.Particle p = particles[i];
  36. Vector3 particleWorldPs;
  37. if(ps.main.simulationSpace == ParticleSystemSimulationSpace.Local)
  38. {
  39. particleWorldPs = transform.TransformPoint(p.position);
  40. }
  41. else
  42. {
  43. particleWorldPs = p.position;
  44. }
  45. p.velocity += (target.position - particleWorldPs).normalized * Time.deltaTime * force;
  46. particles[i] = p;
  47. }
  48.  
  49. ps.SetParticles(particles, particles.Length);
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement