- Home /
 
 
               Question by 
               PJRM · Nov 06, 2017 at 05:01 PM · 
                script.particle systemproblem during runtime  
              
 
              Particle System through Script
Hi. I made this script to create an dust effect in my space, but the particles are not being shown.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 namespace Game.Effects {
    public class ParticleSpaceDust : MonoBehaviour {
       private Transform _T;
       private ParticleSystem _P;
       private ParticleSystem.Particle[] points;
 
       [SerializeField]private Rigidbody playerRigidbody;
       [SerializeField]private int maxParticles;
       [SerializeField]private float dustDistance;
       [SerializeField]private float dustSize;
 
       private void Start () {
          _T = transform;
          _P = GetComponent<ParticleSystem>();
       }
     
       private void Update () {
          // validation
          if (playerRigidbody == null) return;
          if (points == null) CreateDust();
 
          // effects
          /*
          for (int i = 0; i < points.Length; ++i) {
             if (Vector3.Distance(_T.position, points[i].position) > dustDistance) {
                points[i].position = (Random.insideUnitSphere * dustDistance + _T.position);
             } else {
                // move the particles to  opposite direction of the rigidbody velocity
                Vector3 pos = new Vector3(-playerRigidbody.velocity.z, 0f, -playerRigidbody.velocity.x);
                points[i].position = pos + points[i].position;
             }
          }
          */
          _P.SetParticles(points, points.Length);
       }
 
       private void CreateDust() {
          points = new ParticleSystem.Particle[maxParticles];
          for (int i = 0; i < maxParticles; ++i) {
             points[i].position = (Random.insideUnitSphere * dustDistance) + _T.position;
             points[i].startColor = Color.white;
             points[i].startSize = dustSize;
          }
          _P.SetParticles(points, maxParticles);
          _P.Play();
       }
    }
 }
 
               The particle system component is attached to same GO as the script. Here is the Particle System properties. Its a brand new particle with Emission, Shape and Looping offline. 
When I hit play, nothing happen! Help please!
 
                 
                ps-properties.jpg 
                (64.0 kB) 
               
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by PJRM · Nov 06, 2017 at 06:55 PM
Well... it's showing now ( idk how ), but it takes a huge time to the particles show up.
Your answer