Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ParticleTarget : MonoBehaviour {
- [SerializeField]
- private Transform target;
- [SerializeField]
- private float force = 10.0f;
- private ParticleSystem ps;
- // Use this for initialization
- void Start () {
- ps = GetComponent<ParticleSystem>();
- }
- // Update is called once per frame
- void Update () {
- }
- private void LateUpdate()
- {
- ParticleSystem.Particle[] particles = new ParticleSystem.Particle[ps.particleCount];
- ps.GetParticles(particles);
- for(int i = 0; i < particles.Length; i++)
- {
- ParticleSystem.Particle p = particles[i];
- Vector3 particleWorldPs;
- if(ps.main.simulationSpace == ParticleSystemSimulationSpace.Local)
- {
- particleWorldPs = transform.TransformPoint(p.position);
- }
- else
- {
- particleWorldPs = p.position;
- }
- p.velocity += (target.position - particleWorldPs).normalized * Time.deltaTime * force;
- particles[i] = p;
- }
- ps.SetParticles(particles, particles.Length);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement